Accessing Facebook data through the Facebook Graph API and restFB - facebook

When I access Facebook through the Graph API I get only very few entries. For instance if I access the Galaxy S4 fan page through the Graph API I see only four entries:
https://graph.facebook.com/412437702197294/comments/
if I access it through restFB I only get 2:
FacebookClient publicOnlyFacebookClient = new DefaultFacebookClient();
Page page = publicOnlyFacebookClient.fetchObject("GalaxySFour", Page.class);
JsonObject galaxySFourID = publicOnlyFacebookClient.fetchObject("GalaxySFOUR", JsonObject.class);
JsonObject galaxySFour = publicOnlyFacebookClient.fetchObject(galaxySFourID.getString("cover_id") + "/comments", JsonObject.class);
Vector<String> comments = new Vector<String>();
for(int i = 0; i < galaxySFour.length(); i++) {
comments.add("Message: " + galaxySFour.getJsonArray("data").getJsonObject(i).getString("created_time") + ": " + galaxySFour.getJsonArray("data").getJsonObject(i).getString("message"));
}
I'm aware that I cannot get all data, but I didn't expect to get so little. Is there anyway to get more data?

Access via this link : http://facebook.com/412437702197294,
there are only 4 comments. So, https://graph.facebook.com/412437702197294/comments/ return 4 comments is right.
By default, when retrieving data via Facebook Graph API, you only get 20 results.
You can use limit to get more data, such as:
http://facebook.com/412437702197294?limit=500
The maximum limit is 5000.

Related

Facebook API stops at 25 photos

I have tried using the limit parameter for selecting photos from albums on my facebook page. The javascript api just ignores the parameter and according to
https://developers.facebook.com/docs/graph-api/reference/photo/
This endpoint does not have any parameters. So I am trying to figure out how to return more than 25 photos for albums that contain more. Here is the part of my code that returns the photos
FB.api(
'/'+id+'/photos?limit=100',
'GET',
{"fields":"link,source"},
function(response) {
$(location).children().remove();
for ( var i = 0; i < response.data.length; i++) {
$(location).append('<li><img src="'+response.data[i].source+'"/></li>');
}
}
);
If anyone can help me figure out why and or how to get more than 25 results using the photos graph api that would be great!

Retriving Facebook posts from Profile via FB api

I have registered an app in facebook developers program and I can retrieve posts from facebook page using fb api, but I cannot retrieve posts from facebook profile. Should I use some different access token for both page or profile? Is there a different way for retrieving posts from facebook page and profile?
Any help will be appreciated!
You may need the user_status permission.
And you call the posts using this graph query {USER_ID}?fields=statuses
Prerequisite:- You need to have valida FB token for all the request:-
I am answering using c# language.
Step 1:- First you need to get the user's FB id using FB token
I am using Facebook SDK 7.0.6 for querying purpose
here's how to initialize the FB service which we will use in our consecutive calls.
FacebookService facebookService = new FacebookService(facebookToken);
var _facebookClient = new Facebook.FacebookClient(token);
Code snippet
public string GetFacebookID(string facebookToken)
{
dynamic result = _facebookClient.Get("me?fields=id");
if (result.ToString().Contains("id"))
{
return result["id"];
}
return string.Empty;
}
after that you can execute below method to get user's post using FB ID and token
public List<Post> GetPostsForUser(string facebookID)
{
List<Post> posts = new List<Post>();
dynamic result = _facebookClient.Get(facebookID + "/posts"); //Case Sensitive, Posts doesn´t work
if (result.ToString().Contains("data") && result.data.Count > 0)
{
foreach (var item in result.data)
{
posts.Add(new Post
{
ID = item.id,
Story = item.story,
Message = item.message,
Created_Time = Convert.ToDateTime(item.created_time),
Reactions = GetReactions(item.id)
});
}
result = _facebookClient.Get(GetNextURL(result.ToString()));
}
return posts;
}

Facebook Referral URL decode

Sometimes I get burst of visitors from Facebook, which I am curious to know where exactly on Facebook if the page is public, of course!
Is there a way to decode and track back Facebook referral URL to actual page in the Facebook?
URL format is the following:
http://www.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=iAQDjUC4AQHjQeIXcOi8z9jamgyDk8vpuylpdaRT3aHu6Q&s=1
From mobile it is shorter:
http://m.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=BAQFX067m&s=1
Where domain.com is my website for example.
You can extract the URL manually using substr and then apply decodeURIComponent:
function extractFacebookUrl(u) {
u = u.substr(u.indexOf('l.php?u=') + 8); // remove before ?u=
u = u.substr(0, u.indexOf('&')); // remove after &
return decodeURIComponent(u);
}
var link = "http://www.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=iAQDjUC4AQHjQeIXcOi8z9jamgyDk8vpuylpdaRT3aHu6Q&s=1";
var linkMobile = "http://m.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=BAQFX067m&s=1";
document.body.innerHTML = extractFacebookUrl(link) + "<br/>" + extractFacebookUrl(linkMobile);

Facebook Events appear on Google Map

is there a way I can make events on the standard Facebook events app appear on a custom Google Map I've created?
Any tips would be much appreciated.
Given you have the user_events permission, you can access the locations like so:
FB.api("/me/events", function(events) {
if(events.error)
console.error(events);
var map = "http://maps.googleapis.com/maps/api/staticmap?zoom=14&size=512x512&maptype=roadmap&sensor=false";
for(var i = 0; i < events.data.length; i++) {
var point = "&markers=color:blue%7Clabel:S%7C";
point += (events.data[i].venue.latitude + "," + events.data[i].venue.longitude);
map += point;
}
var img = document.createElement("IMG");
img.src = map;
document.body.appendChild(img);
});
I didn't test it, but this should be enough to show an example of how to access the API in the browser and render a map with it's information. This is using Google Maps static API.
I just created a python script, source here.
It queries the given facebook page and it's events and puts the data into a MySQL table. It also contains a Geo-cache library, which combines a local database with the Google Maps Geocoding API, so you can query the longitude and the latitude of the events very fast.

Facebook Graph API and limits

I am working with the Graph API but I have found it to be rather limited. In the news feed on the Facebook website you might see "X and 14 other friends likes Y page." or "X and 3 other friends has changed their profile picture."
In the Graph API it will look like the code below when X and 14 other friends has liked the same page. The Graph API only returns the name of X but not how many friends other than X who have liked the page.
{
application = {
id = 01010101;
name = Pages;
};
comments = {
count = 0;
};
"created_time" = "2011-08-15T08:35:47+0000";
description = "Description of page.";
from = {
id = 1111;
name = "X";
};
icon = "---";
id = "http://static.ak.fbcdn.net/rsrc.php/v1/yN/r/xC785tTCIQO.gif";
link = "http://..../";
name = "Y";
picture = "---";
type = link;
"updated_time" = "2011-08-15T08:35:47+0000";
}
I don't see any way to get this information. Am I right or am I missing something?
It depends on the type of object you are accessing. Recently, Facebook have begun to hide useful info such as who specifically liked something, I'd imagine because they don't want people writing analytics packages for facebook but would prefer users to use the facebook system.
I know when it comes to images you can only get the number of likes , but not who they actually came from.
Your best bet is to use FQL which still lets you retrieve some of this information.