Semiocast API tutorial
Facebook

About

This chapter of the tutorial explains how to analyze Facebook messages with Semiocast API.

Prerequisite

It is recommended to have read the Raw text section first to get familiar with the Semiocast API.

Analyze facebook posts and profiles

Semiocast API analyzes and filters Facebook posts and Facebook user profiles. Read micromessage analysis documentation for a complete list of features, languages recognized, location's formats accepted, and results provided by this query.

Sample Facebook posts retrieval

First get a set of posts from Facebook search and store them in a file named posts.json:

curl "http://graph.facebook.com/search?q=phone&type=post&limit=10" > posts.json

This should save some Facebook posts in the file posts.json. Check the content of the file to make sure you successfully retrieved a sample of Facebook posts.

You should have something like:

{"data": [ {"id":"1321463701_133457140006555","from":{"name":"...","id":"..."},"message":"...",...}, ... {"id":"100000313938837_113658298680694","from":{"name":"...","id":"..."},"message":"...",...} ], "paging":{"previous":"http://graph.facebook.com/...","next":"http://graph.facebook.com/..."} }

This step is just intended for the tutorial, you can use your own sample.

Facebook posts analysis

Once you have some posts in the file posts.json, make a call to the Semiocast API to analyze your data:

curl -E semiocast-api.pem:PASSWORD --data-urlencode data@posts.json https://api.semiocast.com/1/analyze/facebook.json

This will result in:

[{"id":"1321463701_133457140006555","language":{"script_code":"arab","language_code":"ar"}}, {"id":"100000313938837_113658298680694","language":null}, {"id":"1527822784_120619801313888","language":{"script_code":"latn","language_code":"fr"}}, {"id":"1213202689_126618760707705","language":{"script_code":"latn","language_code":"fr"}}, {"id":"524729285_127046587335054","language":{"script_code":"latn","language_code":"en"}}, {"id":"789383717_109859349061859","language":{"script_code":"latn","language_code":"fr"}}, {"id":"1517765515_131055870250552","language":{"script_code":"latn","language_code":"fr"}}, {"id":"685544721_131039386916329","language":{"script_code":"latn","language_code":"fr"}}, {"id":"626869454_103392136379417","language":{"script_code":"latn","language_code":"fr"}}, {"id":"1032605868_133084646709738","language":{"script_code":"latn","language_code":"fr"}}]

Returned result associates to each status a message language. language is null if there are no messages nor descriptions to analyze. Since Facebook post does not contain location information, no location is returned.

Facebook Graph API does not provide an official field to add metadata inside posts. If you want to have analysis result inside each message, Semiocast API can add an unofficial annotations field to contain this information.

curl -E semiocast-api.pem:PASSWORD -d output=enriched --data-urlencode data@posts.json https://api.semiocast.com/1/analyze/facebook.json
{"data":[ {"id":"1321463701_133457140006555", "message":"u0623u0642u0648u064a u062au0627u0644u064au0641u0648u0646 ...", "annotations":[{"language":{"script_code":"arab","language_code":"ar"}}] }, ...], "paging":...}

This analysis works on user news feed:

curl "https://graph.facebook.com/me/home?access_token=YOUR_FACEBOOK_TOKEN" > my_home.json
curl -E semiocast-api.pem:PASSWORD --data-urlencode data@my_home.json https://api.semiocast.com/1/analyze/facebook.json

Semiocast API is also able to analyze user profiles or your friends lists. Either use this line to retrieve specific users' profile:

curl "https://graph.facebook.com/?ids=arjun,vernal&access_token=YOUR_FACEBOOK_TOKEN" > profiles.json

or this line, for your friends:

curl "https://graph.facebook.com/me/friends?access_token=YOUR_FACEBOOK_TOKEN&fields=name,location" > profiles.json

Then call Semicost API with:

curl -E semiocast-api.pem:PASSWORD --data-urlencode data@profiles.json https://api.semiocast.com/1/analyze/facebook.json

This will give you the following result:

[{"id":"7901103","location":{"country_code":"US","city_name":"San Francisco"}}, {"id":"9074","location":null}]

Alternate output

As for posts, Semiocast API can provide enriched user profiles containing inferred information:

curl -E semiocast-api.pem:PASSWORD -d output=enriched --data-urlencode data@profiles.json https://api.semiocast.com/1/analyze/facebook.json
{ "arjun":{ "id":"7901103","name":"Arjun Banker","first_name":"Arjun","last_name":"Banker", "link":"http://www.facebook.com/Arjun", "location":{"id":114952118516947,"name":"San Francisco, California"}, "gender":"homme", "annotations":[{"location":{"country_code":"US","city_name":"San Francisco"}}]}, "vernal":{ "id":"9074","name":"Mike Vernal","first_name":"Mike","last_name":"Vernal", "link":"http://www.facebook.com/vernal","gender":"homme", "annotations":[{"location":null}]} }

Filter facebook posts and profiles

Semiocast API provides a method to filter micromessages according to message language or user location. It allows to get only posts written in a specific language or user from a specific location.

Read micromessage filtering documentation for a complete list of features, parameters and results provided by this query.

Filtering by language

For instance if you want only messages written in english or arabic:

curl -E semiocast-api.pem:PASSWORD -d languages=ar,en --data-urlencode data@posts.json https://api.semiocast.com/1/filter/facebook.json

Will return:

[{"id":"1321463701_133457140006555","language":{"script_code":"arab","language_code":"ar"}}, {"id":"524729285_127046587335054","language":{"script_code":"latn","language_code":"en"}}]

Returned result contains only messages written in arabic or english. Each message id is associated to identified language.

Filtering by location

If you want only profiles from a specific location, like United States. You can analyze user profiles:

curl -E semiocast-api.pem:PASSWORD -d locations=US --data-urlencode data@profiles.json https://api.semiocast.com/1/filter/facebook.json

Will return the following:

[{"id":"7901103","location":{"country_code":"US","city_name":"San Francisco"}}]

Filtering according to city name will be added later.

Further reading

Read micromessage analysis documentation for a complete list of features, languages recognized, location's formats accepted, and results provided by this query.