I would like to retrieve photos from a facebook group using the GraphAPI. Based on FB Docs I don't see any connections to photos. I would like to get the photos and the users who uploaded them.
Graph API:
http://graph.facebook.com/GROUP_ID/?fields=name,description,albums
return
{
"name": "Group name",
"description": "Group description",
"id": "GROUP_ID",
"albums": {
"data": [
{
"id": "GROUP_ALBUM_ID",
"name": "GROUP_ALBUM_NAME",
"link": "GROUP_ALBUM_LINK",
"created": 1352388257,
"modified": 1352388257,
"cover_pid": 444427468954616,
"count": 22
}
],
"paging": {
"next": "https://graph.facebook.com/GROUP_ID/albums?limit=25&offset=25"
}
}
}
and next query
http://graph.facebook.com/GROUP_ALBUM_ID/photos?fields=picture,source,name&type=uploaded
Ive been digging a bit in the same issue.
We have a group album which is has this url
https://www.facebook.com/media/set/?set=oa.10150651435446985
So the ID seems to be oa.10150651435446985
Another empty album gets album gets the set-id oa.10150652583791985
A note in the same group id 10150652589396985
Notice the similarity in ID's.
The direct link: http://facebook.com/10150651435446985 works to go to the album.
The album is created by user 1128233556 and the groupid is 184760601984.
Other, individual (not in an album) group photos are in "set" o.184760601984 where the digit represents the group id.
So what does "o" and "oa" stand for? a=album, o=?
Pictures have the following URL: https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/s720x720/420015_3293876662264_1128233556_33234982_110700674_n.jpg
420015_3293876662264_1128233556_33234982_110700674
??????_PHOTOID_______USER_______????_____?????????
Who can make something out of al that?
I have the same problem / here is my partial answer, which remains kind of hack :
one can retrieve photos posted on a group via the FQL group.stream or the GraphAPI group.feed (playing around with the facebook graphApi explorer or the fql query/multiquery test console).
This way you can retrieve all needed information, included a valid id to retrieve the photo, and one to retrieve the object from the graph.
BUT, this is only valid for individual photos.
since my previous answer was deleted, i won't repost it here, but remind that my similar problem is detailed in this thread FQL or GraphAPI unable to retrieve PHOTO ALBUM or VIDEO posted on a GROUP , which, if ever solved, might even as well help people for this very problem here.
Thomas
I don't think Albums in groups R treated like albums on Profile pages. The pics have aid ="0" Even if they are part of albums.
I used The Image below:
https://www.facebook.com/photo.php?fbid=10151350034089218 is the link to the image. And you can guess where I got the object_ID.
In this example 10151350034089218 is the object_ID for an image in an album for my group "T_Group" The link to the group is https://www.facebook.com/groups/217697621700825/.
You can then run the FQL query
SELECT aid
FROM photo
WHERE object_id = 10151350034089218
you'll get
aid
====
0
Even though it is part of an album "Hugh Laurie".
I tried the same FQL query with images in albums on my profile and they always returned an aid with some Number other than 0.
I plan on posting to Facebook bugs, I hope I get a fix. Unless its running as intended.
I tried:
SELECT pid
FROM photo_tag
WHERE subject =217697621700825
...and I got PIDs to photos posted to the group page not images in albums.
I wish I had found a more direct method, but this appears to have promise:
get /me/groups or /me?fields=groups to get the groups ids.
From that, get {group_id}/feed?type=photo This returns just the photos from the feed, but all you really get (toward this goal) is the photo's id (returned as object_id).
Then for each photo you can get /{object_id} which returns all the links to the various sizes of the image.
I did this research in Facebook Graph Explorer, so keep that in mind as you try to implement it.
Rob
Related
I'm using the following Graph Api query in order to receive the likes and comments counts on all the photos in an Album inside my page:
https://graph.facebook.com/v2.2/album_id?fields=photos.limit(250){likes.limit(1),comments.limit(1),id,source},likes.limit(1)&access_token=my_access_token
I want to to also receive each one of these pictures shares count, but the share count is not connected to the photo end point, Its connected to the page_story_id.
So, in order to receive all the shares count i'm going to need to query each of those individually, which doesn't make sense when you have an album with 200 pictures (not to mention an album with 500 pictures).
FQL is deprecated after v2.1 so I can't use the FQL to get this (which will defiantly ease everything for me).
Isn't there an easier way to do so?
Update
Thanks to #CBroe comments, this is my batch:
[
{
"method":"GET",
"name":"get-photos",
"relative_url":"951337131548012?fields=photos.limit(250){likes.limit(1),comments.limit(1),id,source,page_story_id},likes.limit(1)"
},
{
"method":"GET",
"relative_url":"/?ids={result=get-photos:$.photos.data.*.page_story_id}"
}
]
Now it does return all the photos post objects, but how can I query them all the specific field? like add ?fields=shares
ok after struggling with this for few hours, and thank to #CBroe help I found the right batch request for my needs and it involves both batch and Graph API multiple requests.
[
{
"method":"GET",
"name":"get-photos",
"relative_url":"951337131548012?fields=photos.limit(250){likes.limit(1),comments.limit(1),id,source,page_story_id},likes.limit(1)"
},
{
"method":"GET",
"relative_url":"/?ids={result=get-photos:$.photos.data.*.page_story_id}&fields=shares"
}
]
by adding &fields=shares i'm filtering the fields of inner results of the multi request.
Hope it helps someone :)
Insights API works properly for link feed but it doesn't work for photo feed. For photo feed, Insights API returns 0 or empty even though Insights page shows a high reach and engagement rate.
Here is the url pattern of my photo feed:
https://www.facebook.com/[PAGE]/photos/a.xxx.xxx.[PAGE ID]/[POST ID]/
Insights API returns:
{
"id": "[PAGE ID]_[POST ID]/insights/post_story_adds_by_action_type_unique/lifetime",
"name": "post_story_adds_by_action_type_unique",
"period": "lifetime",
"values": [
{
"value": [
]
}
],
"title": "Lifetime Talking About This (Post) by action type",
"description": "Lifetime: The number of unique people who created a story about your Page post by interacting with it. (Unique Users)"
}
I've been struggeling with the same questions... one thing I can tell you is, that you most likely used a wrong id for you photo post.
Please ensure that you ONLY use ID's retrieved by a facebook api. So this is a sample process:
1. Note your page-id
2. Use GRAPH to query <url-to-graph>/<page_id>/feed?access_token=<your_token>
3. From the response, take the photo-post-id you want to analyze
4. Use GRAPH to query <url-to-graph>/<id_from_step_3>/insights/?access_token=<your_token>
5. Check the metrics returned from step 4 and enjoy!
Please keep in mind that there's an undocumented need to add your page_id to any post_id. So every replacement of {post-id} as it is written in the FB api's will be _.
Hope that helps...
When querying posts from a group the photos are not returned most of the time even though the posts have photos.
We have a working app that uses those photos and starting from about 24 hours ago we almost don't get any photos.
For example, the following post - 45245752193_10152313354342194
has photos and it's also public, but the api doesn't return the photos:
This is my query:
45245752193_10152313354342194?fields=attachments,full_picture,picture
Full_picture and picture don't exists in the response, and in the attachment I get this:
"description": "This attachment may have been removed or the person who shared it may not have permission to share it with you.",
"title": "Attachment Unavailable",
"type": "unavailable"
I also tried to get the photos in two different ways and it didn't work.
1.Querying {group_id}/feed?fields=attachments,full_picture,picture,object_id,from
I get the same error string as before in the attachment field, picture and full_picture are empty.
2.Using fql with the following query:
SELECT source_id,attachment,post_id, message, like_info,comment_info,created_time, share_count,actor_id FROM stream WHERE source_id in (45245752193) and
Here the attachments field is empty.
According to the developer bug centre this is a valid bug, and Facebook are looking to fix this issue.
https://developers.facebook.com/bugs/752853894779368/
I wrote a query, trying to all the comments, given on my albums. The query I use is the following :
SELECT fromid, user_likes, text, time FROM comment
WHERE object_id IN
(
SELECT object_id FROM photo
WHERE aid IN (
SELECT aid FROM album WHERE owner=me()
)
)
In my case, when I test it on the developers site, it just returns:
{
"data": [
]
}
So I figured my query wasn't wrong because it returns no error so I asked a friend to try it and he did get all his comments on albums. The test page I used it the following :
http://developers.facebook.com/tools/explorer/?fql=SELECT%20fromid%2C%20user_likes%2C%20text%2C%20time%20FROM%20comment%20%0AWHERE%20object_id%20IN%20%0A(%20%0A%20%20%20%20SELECT%20object_id%20FROM%20photo%0A%20%20%20%20WHERE%20aid%20IN%20(%20%0A%20%20%20%20%20%20%20%20SELECT%20aid%20FROM%20album%20WHERE%20owner%3Dme()%20%0A%20%20%20%20)%0A)%0A
And yes, I do have a valid access token because the following query does work:
SELECT object_id FROM photo
WHERE aid IN (
SELECT aid FROM album WHERE owner=me()
)
Is it possible it doesn't work because I'm a new user on facebook? Or can it be that it's a privacy setting? I compared all my privacy setting (album and profile) with my friend and we have exactly the same so I don't think so.
Also when I share an album with a link (go to album, click on wheel, share, copy link), people have to log in on facebook before they can see the album and if my friend does the same, people can watch it without being logged in (like it is suppose to work). Maybe this has something to do with it?
I tried google, facebook help, calling facebook and even looking for answers on the developer pages and this forum but no luck. So you guys are basically my final hope...
Thanks a million
De Wesp!
you may have got this error
{
"error": {
"message": "(#601) Parser error: unexpected end of query.",
"type": "OAuthException",
"code": 601
}
}
this is because when you creating an app you should create a token access for your apps.
Please let me know if it does not work.
Is there a way to get the ID of the picture that is the current profile picture for a user?
Edit: OK, seems there is no trivial way to get the ID!
However, it appears from random testing that every user has a single album with attribute type="profile", and the first image in this album is always the profile picture, so it is possible to get the ID of the profile picture that way. Can some more experienced with Facebook confirm that this is indeed always the case?
You can get the users public profile photo from the following url:
https://graph.facebook.com/[id]/picture
Reference:
http://developers.facebook.com/docs/reference/api/
The answer seems to be yes
e.g., the photos in an album have an ID (the profile photo is a different object though, which a different FB ID). An ID for every object is a core concept of FB's new graph API: Every object in the social graph has a unique ID.
Indeed, data request i have ever made through the FB Graph API returns (when successful) a response in the form of a JSON array, comprised of nested ID-Value pairs, e.g. the education field from a User object:
"education": [
{
"school": {
"id": "126533127390327",
"name": "Massachusetts Institute of Technology"
},
"year": {
"id": "140829239279495",
"name": "1992"
},
"concentration": [
{
"id": "192578844099494",
"name": "Computer Science"
}
],
"type": "College"
}
The profile photo is a connection of the User object (i.e., every FB object has Fields and Connections).
According to the table in the relevant FB Developer Page, a call to the Graph API requesting picture (user's profile photo(s)) returns a string which is the URL for the user's profile picture.
But why doesn't this same call return the user's profile photo ID?
The reason i suppose is that the URL returns:
Graph API : User Properties
The user's profile photo is not there, but in an adjacent node:
Graph API : User : Connections : picture
(See FB Documentation for Graph API structure here).
When you make that API call, examine the Request Headers, and in particular, the Request URL; when you do, you'll see something like this:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/32093_100005743929541_5467982_q.jpg
The string between the underscores (100005743929541) is the user ID. this is easy to verify by making another call to the Graph API. From your browser location bar (assuming you are logged into Facebook) just enter:
https://graph.facebook.com/me
So again, the first item in that JSON string is the user's FB ID. Given that, it seems to me that if user profile ID does indeed have its own ID, then that string (user's FB ID) plus the two smaller adjacent strings of integers on either end of the ID, should be it--in other words, 32093_100005743929541_5467982 in the Request URL above.
Finally, perhaps the best way to answer this is by using the new Graph API Explorer. (I just tried to verify this, but my requests are hanging.)
There is one more simple way to accomplish this task.
Fetch all facebook albums by https://graph.facebook.com/me/albums?access_token=.
Loop into the albums and check if object type == 'profile'.
Get the value of object cover_photo where type == 'profile'.
This value of cover_photo is the id of profile pic of the user.
You can check it by https://graph.facebook.com/<cover_photo value>?access_tokne=
I don't know if you still need this but this is the way I did it in PHP:
$albumsfb = $facebook->api('/me/albums/?fields=type');
$albumsfb = $albumsfb['data'];
foreach ($albumsfb as $albumfb) {
if ($albumfb['type']=='profile'){
$albumprofile = $albumfb['id'];
break;
};
}
$photoprofilefb = $facebook->api('/'.$albumprofile.'/?fields=cover_photo');
$photoprofilefb = $photoprofilefb['cover_photo'];
$photoprofilefb = $facebook->api('/'.$photoprofilefb);
$fotoperfilfburl = $photoprofilefb['source'];
Instead of "me", put the user id that you want?
http://graph.facebook.com/<SOCIAL-ID>/picture?type=<small|normal|album|large|square>
SOCIAL-ID = Facebook returned social id.
small|normal|album|large|square = size of image.
I recently tried to like one of my friend's profile pictures from the Graph API explorer
Here's how I got the id of his current profile pic:
fields=friends..fields(albums.fields(photos.fields(id,name,link),name))
If you have used the Graph API explorer, you might be aware of the above line of code that's generated in the textEntry when you tick the checkboxes. The limit size is up to you, I just kept it 1 to receive the JSON object quickly (without the limit, it took me 5 minutes to get the JSON object containing a lot of information).
So here are the things you need to check in the Graph API (maintain the order):
Friends
Within Friends Albums
Within Albums Name and Photos (Within Photos the id and name of the photo)
I made a PHP script to like all the profile pictures of my friends :)