I'm using Facebook Graph API to get all the photos of a user graphPath: me/albums and find something weird with Timeline Photos album.
Photos exist in Timeline album on Facebook, but not returned from API call graphPath/{timeline_photos_album_id}/photos, or they are returned with lower number of photos.
What is the problem?
Logs:
Calling for albums graphPath: me/albums:
.....
{
"can_upload" = 0;
count = 3; !!!!!!!!!!!
"created_time" = "2013-06-18T10:43:27+0000";
description = cool;
from = {
id = 100006100533891;
name = "Mike Mike";
};
id = 1387760311437307;
link = "https://www.facebook.com/album.php?
fbid=1387760311437307&id=100006100533891&aid=1073741829";
name = "Timeline Photos";
privacy = everyone;
type = wall;
"updated_time" = "2013-06-18T10:47:53+0000”;
},
.....
Calling for album photos graphPath/{timeline_photos_album_id}/photos:
{
data = (
);
}
Unfortunately "it is not a bug, it is by design".
I tried the following (with "user_photos" permission) and it works:
Fetch the album photo count for my user:
https://graph.facebook.com/me/albums?fields=id,count&access_token={access_token}
The result is
{
"data": [
{
"id": "{album_id}",
"count": 161,
"created_time": "2010-11-05T15:41:42+0000"
},
....
}
Then query for the photos of this album:
https://graph.facebook.com/{album_id}/photos?fields=id&limit=500&access_token={access_token}
The result is
{
"data": [
{
"id": "{photo_id1}",
"created_time": "2013-12-29T09:59:52+0000"
},
{
"id": "{photo_id2}",
"created_time": "2013-12-17T10:40:26+0000"
},
...
}
I count the correct number of 161 ids in the result. So everything seems to work fine.
You can also test this via FQL:
https://graph.facebook.com/fql?q=select+pid+from+photo+where+album_object_id+=+{album_id}+limit+1000&access_token={access_token}
there have been changes in the FB API recently, did you try to add the fields you want to get back in the result from the API? In the past, API always returned "standard fields", newest you always have to provide a list of fields of what you want to have back in the result such as ....fields=name,id...
I think you are missing the user_photos permission in the Access Token. The end point:
/{timeline_photos_album_id}/photos is working perfectly fine for me when I tried it using the Graph API Explorer to retrieve photos from my Timeline photos album. And, I don't think that it is necessary to provide the fields.
I'll suggest you should try the same using the Graph API Explorer. Just press the Get Access Token button on the top right and check the user_photos permission to test your request.
In case you are getting lesser results, you can try your query using pagination options limit and offset. This sometimes returns more results as compare to normal(nothing about this on docs, just my personal experience). Something like:
{timeline_photo_album_id}/photos?limit=500&offset=0
But again, as you pointed out, there are strange things going on with the API. Take a look at this article. This article refers to it as an expected behavior of the API!
Related
I want to get likes on post on the page: "The Jungle Book"
I am able to get the likes of the page using url:
https://graph.facebook.com/" + pageId + "?fields=likes&access_token=" + ACCESS_TOKEN
I have read the documentation
and find that i will get the likes(total count) of the post only returned when the flag summary=true is set
The response should look like this
{
"likes": <somecount>,
"id": "151505938209071_1507814655911519"
}
I am able to get the likes on page but not able to get total number of likes on the particular post on that page.
Can anyone help me regarding how I should set the URL or is there any other way to do it.
From what you described it sounds like it should be like this:
https://graph.facebook.com/" + pageId + "?fields=likes&summary=true&access_token=" + ACCESS_TOKEN
The above is your existing URL with summary=true in between the fields=likes and access_token parameters
However you may be interested in this answer
Quote:
Couldn't find this in the documentation but multiple calls to the API are not necessary. You can use summary when querying a feed or multiple posts. Specify this in the fields parameter.
https://graph.facebook.com/PAGE_ID/feed?fields=comments.limit(1).summary(true),likes.limit(1).summary(true)
This will return a response like this.
{
"data": [
{
....
"summary": {
"total_count": 56
}
...
},
{
....
"summary": {
"total_count": 88
}
...
}
]
}
This will be much faster than making individual requests for each object just to get the number of comments or likes.
Can any body tell me how to get the photo Like Info from graph explorer?I tried this fql query
select like_info from photo where object_id=PHOTO ID
Using this query This photo Id-10152460216420695 gives me result
{
"data": [
{
"like_info": {
"can_like": true,
"like_count": 2118,
"user_likes": false
}
}
]
}
But this photo Id-551468638224054 gives me result
{
"data": [
]
}
This two photo are the public and both have more than 1 like.So why the last one can not give me the right result?Waiting for your help...
You can use :
select like_info from photo where object_id="PHOTO ID"
If it fails than it means The photo is invisible for graph api.
One of those photos may not be available via the API due to privacy settings. Even though a photo is public on Facebook itself, there may be other reasons why the piece of content isn't emitted via the API.
There is the question about fetching count of user friends via FaceBook API.
I want to get the number of friends only have USER_ID of the any facebook user. As I know I can get it using FQL like:
SELECT friend_count FROM user WHERE uid = X
But for some users this value is null or there is no value. Please advice is there another way to get this value?
That user might be keeping that information private. In that case, you cannot fetch that information.
You just check the following link. You need to generate token (by clicking on Get Token you will get it) with data you want from facebook API, need to select friends option to get the friend count.
https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname%2Cfriends&version=v2.8
FB.api(
'/me',
'GET',
{"fields":"id,name,friends,link,email,gender,picture,first_name,last_name,cover"},
function(response) {
// Insert your code here
}
);
after executing this you will get this in response as
{
"id": "XXXXXXXXXX",
"name": "Test test",
"friends": {
"data": [
],
"summary": {
"total_count": 14
}
}
}
total_count will be your friend count
I am new in unity and trying to integrate Facebook unity SDK. But i am not able to find current logged-in user name. It will return only userId and accessToken. How to get login name after FB.Login("email")
After you login, you can get the name with:
FB.API("me?fields=name", Facebook.HttpMethod.GET, <your callback here>);
After calling the API
FB.API("me?fields=name", Facebook.HttpMethod.GET, NameCallBack);
get the exact name from the JSON like this:
void NameCallBack(FBResult result)
{
IDictionary dict = Facebook.MiniJSON.Json.Deserialize(result.Text) as IDictionary;
string fbname = dict["name"].ToString();
}
My best guess if I was to look somewhere is to make use of that userId and FQL to query Facebook for the name of the user.
For instance using the Graph API Explorer:
https://developers.facebook.com/tools/explorer
I used the following query:
Select name from user where uid = [userId]
It returned the following JSON string:
{
"data": [
{
"name": "myName"
}
]
}
I think you can use https://developers.facebook.com/docs/php/howto/profilewithfql/ to get an idea of how to query the FB.API to perform a FQL query.
FQL Guide: https://developers.facebook.com/docs/technical-guides/fql/
I'm using Graph API to get the wall post of a fan page.
I noticed the Facebook iOS app itself is able to determine the exact ratio for its placeholder.
http://developers.facebook.com/tools/explorer?method=GET&path=facebook%2Ffeed%3Ffields%3Dpicture
{
"data": [
{
"picture": "http://photos-b.ak.fbcdn.net/hphotos-ak-frc1/247019_457846347622804_946521095_s.jpg",
"id": "20531316728_10151883063741729",
"created_time": "2013-05-02T16:57:25+0000"
},
:
:
:
{
"picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-ash4/223257_10151498310776729_930531604_s.jpg",
"id": "20531316728_10151498193061729",
"created_time": "2012-10-05T18:42:38+0000"
}
],
"paging": {
"previous": "https://graph.facebook.com/20531316728/feed?fields=picture&limit=25&since=1367513845",
"next": "https://graph.facebook.com/20531316728/feed?fields=picture&limit=25&until=1349462557"
}
}
There it contains no information of the pictures' dimension in the API response, which I'd like to have a correct placeholder size with my custom client like the Facebook iOS app.
I tried adding /facebook/feed?fields=picture,width,height but no luck in retrieving the corresponding information.
Is there a possible way to retrieve the pictures's height and width param from the API itself?
No, API doesn't return ALL picture's dimensions based on post feed from /page_id/feed or stream table.
I mentioned all because, what you can do is:
SELECT post_id, created_time, actor_id, attachment, message FROM stream WHERE source_id=PAGE_ID AND created_time<now() LIMIT 50
If the post type is photo:
If the post type is video:
If the post type is link start with fbexternal (extract parameter w and h):
If the post type is link without fbexternal (facebook photo), we stuck here!:
Code Prototype:
if attachment:
image_url = attachment.media[0].src
if image_url:
m = image_url.photo.images
if m:
if m.src == image_url:
image_width = m.width
image_height = m.height
else: #no dimensions info
if host by fbexternal:
#extract parameter w and h from https://fbexternal-a.akamaihd.net/safe_image.php?d=AQBhfbzbNudc_SE8&w=130&h=130&url=http%3A%2F%2F
image_width = 130
image_height = 130
else:
Stuck here, very hard to get extract photo id based on this url, a lot of work!
In conclusion, i highly recommend you to get image width and height after download photo. For example, PHP have getimagesize function and python have Python Imaging Library (PIL).
I'm not sure if there's an easier way of getting the width and height you need but here's a sure but kinda long-winded way.
Taking your example, the ID that you see for the first picture "20531316728_10151883063741729" isn't actually the ID for the picture. It's for the post that the picture is in.
What you can do, is query for that postID
http://developers.facebook.com/tools/explorer?method=GET&path=20531316728_10151883063741729
then it will expose the picture's object_id 457846347622804 (do a search and you'll see what I mean). now you query for that picture's ID and you'll have your width and height served.
http://developers.facebook.com/tools/explorer?method=GET&path=457846347622804
From then on you should be able to get the ratio you need.
If anyone has an elegant way of getting this done, I'd love to know too.