Facebook Graph API retrieving friends' images - facebook

I'm trying to get all the ids of all my friends along with their profile image. I'm using https://graph.facebook.com/me/friends?fields=picture&access_token=[myToken]
I'm getting this returned:
{
"data": [
{
"id": "xxx",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/xxx_q.jpg"
}
The picture url that returns is for a really small image. How can I get a larger image?

Recommended
According to Doc (section "Pictures"), url of profile's photos can be built with the user id
For example, assuming user id is in $id :
"http://graph.facebook.com/$id/picture?type=square"
"http://graph.facebook.com/$id/picture?type=small"
"http://graph.facebook.com/$id/picture?type=normal"
"http://graph.facebook.com/$id/picture?type=large"
Hack
http://profile.ak.fbcdn.net/hprofile-ak-snc4/xxx_q.jpg
You can replace the q parameter with s or b
:)

Related

How to get instagram media metrics ? Cannot get any media info using ig media id, Instagram graph api

I have created different API queries on searching hashtags and searching recent media with that. This all works fine. but when I grab the ID from media objects from the recent_media query and try to query them separately since then I'm able to query more data. It won't work.
https://graph.facebook.com/v7.0/ig_hashtag_search?access_token={token}&user_id={user_id}&q=hashtag_name
This returns
"data": [
{
"id": "17843780662045901"
}
]
Then I query
https://graph.facebook.com/v7.0/17843780662045901/recent_media?access_token={token}&user_id={user_id}&fields=id,media_url
with result
"data": [
{
"id": "17939405797365335"
},
{
"id": "17868693508835640"
},
and then I try to access media with
"get graph.facebook.com/{graph-api-version}/ig_media_id?fields=id,username" endpoint
I get
{'error':
{'message': "Unsupported get request. Object with ID '17930129249499764' does not
exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at
https://developers.facebook.com/docs/graph-api", 'type': 'GraphMethodException',
'code': 100, 'error_subcode': 33, 'fbtrace_id': 'A0mF0lmOv0VzfO-dN6NTTFA'}}
Following permissions granted at standard access level to my facebook ap:
'instagram_basic',
'pages_show_list',
'pages_read_engagement'
What is the source of problem?
And Is there an alternative wethod to get owner username of an media from media id or media_url using graph api?
Thanks in advance,

How to query facebook with FQL to get usernames who liked and commented on a post or a photo

Ok what i want to do is simple but i am not sure it can be done or not
Here my post and image that i want to query
Original share image :
https://www.facebook.com/MonsterMMORPG/photos/a.551985868170404.1073741825.198765706825757/694573437244979/?type=1
The reshare of the image
https://www.facebook.com/MonsterMMORPG/posts/699889243380065
Now i want to get people who liked image and post and also commented on them
I am trying to get userids of who liked via FQL like below but it returns nothing
SELECT user_id FROM like WHERE post_id=699889243380065
I am doing this at graph api explorer panel here screenshot
first image works second fails
You can use Facebook-graph-api to get your list of likes, as follows:
https://graph.facebook.com/v2.0/699889243380065/likes
(with valid tokens of course)
You'll receive the following list:
{
"data": [
{
"id": "xxx",
"name": "xxx"
},
{
"id": "xxx",
"name": "xxx"
},
etc
To get list of comments via graph-api:
https://graph.facebook.com/v2.0/699889243380065/comments

Facebook Real-Time updates: comment on post vs comment on album

Status entry comment:
{"object":"page","entry":[{"id":"106182246249179","time":1386582683,"changes":[{"field":"feed","value":{"item":"comment","verb":"add","comment_id":"185457974988272_294727","parent_id":185457974988272,"sender_id":106182246249179,"created_time":1386582683}}]}]}
Album comment:
{"object":"page","entry":[{"id":"106182246249179","time":1386581446,"changes":[{"field":"feed","value":{"item":"comment","verb":"add","comment_id":"185444231656313_190183","parent_id":185444231656313,"sender_id":100006218707108,"created_time":1386581446}}]}]}
They seem impossible to distinguish. However, the first one's real post id is pageid_parentid = 106182246249179_185457974988272. If you try to do the same thing with the album comment to get the feed from the stream FQL table, you won't get anything (or an exception with graph api).
Has anyone found a way to distinguish somehow between the two?
Yes.
First you need the object_id
object_id=pageid_parentid
Make this api call with the object id:
GET https://graph.facebook.com/v2.9/{object-id}?fields=type,status_type&access_token=token
The response should look something like this if the parent is a post:
{
"type": "status",
"id": "106182246249179_185457974988272"
}
If it's an album, it will look like this:
{
"type": "photo",
"id": "106182246249179_185457974988272"
}

How to get the right Data to an external URL and the right ID through the API?

is there a possibility to get more informations to a specific url e.g. preview image, title and short description through the open graph? If you do something like this, you only get the "shares" //graph.facebook.com/http://www.google.de
It's a bit confusing, when I get the ID via FQL through the object_url Table I get a different ID to the ID I get from the Debugger.
Getting the ID:
//graph.facebook.com/fql?q=SELECT%20url,id,type,site%20FROM%20object_url%20WHERE%20url%20=%20%22http://google.de%22
Result: "id": 6319338796</pre>
Trying to get the Data with that ID failed (acces token needed)
//graph.facebook.com/6319338796/
"message": "An access token is required to request this resource."
Get the ID with the Debugger:
//developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fgoogle.de
Getting the Result from ID 438699604740 (no problem):
//graph.facebook.com/438699604740
{
"url": "http://www.google.de/",
"type": "website",
"title": "Google",
"image": [{"url": "http://www.google.de/images/google_favicon_128.png"}
],
"updated_time": "2012-12-19T15:26:32+0000",
"id": "438699604740"
}
I am just wondering, why there are two different object IDs for the same URL and why do I need for the one an acces_token and not for the other?
The question is, how to get the right Data and the right ID throug the API? Or are there any restrictions to get these Data from a URL?
Thanks for help!

Facebook Graph API : get larger pictures in one request

I'm currently using the Graph API Explorer to make some tests. That's a good tool.
I want to get the user's friend list, with friends' names, ids and pictures. So I type :
https://graph.facebook.com/me/friends?fields=id,picture,name
But picture is only 50x50, and I would like a larger one in this request.
Is it possible ?
As described in this bug on Facebook, you can also request specific image sizes now via the new API "field expansion" syntax.
Like so:
https://graph.facebook.com/____OBJECT_ID____?fields=picture.type(large)
The best way to get all friends (who are using the App too, of course) with correct picture sizes is to use field expansion, either with one of the size tags (square, small, normal, large):
/me/friends?fields=picture.type(large)
(edit: this does not work anymore)
...or you can specify the width/height:
me/friends?fields=picture.width(100).height(100)
Btw, you can also write it like this:
me?fields=friends{picture.type(large)}
you do not need to pull 'picture' attribute though. there is much more convenient way, the only thing you need is userid, see example below;
https://graph.facebook.com/user_id/picture?type=large
p.s. type defines the size you want
plz keep in mind that using token with basic permissions, /me/friends will return list of friends only with id+name attributes
You can set the size of the picture in pixels, like this:
https://graph.facebook.com/v2.8/me?fields=id,name,picture.width(500).height(500)
In the similar manner, type parameter can be used
{user-id}/?fields=name,picture.type(large)
From the documentation
type
enum{small, normal, album, large, square}
Change the array of fields id,name,picture to id,name,picture.type(large)
https://graph.facebook.com/v2.8/me?fields=id,name,picture.type(large)&access_token=<the_token>
Result:
{
"id": "130716224073524",
"name": "Julian Mann",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15032818_133926070419206_3681208703790460208_n.jpg?oh=a288898d87420cdc7ed8db5602bbb520&oe=58CB5D16"
}
}
}
You can also try getting the image if you want it based on the height or width
https://graph.facebook.com/user_id/picture?height=
OR
https://graph.facebook.com/user_id/picture?width=
The values are by default in pixels you just need to provide the int value
I researched Graph API Explorer extensively and finally found full_picture
https://graph.facebook.com/v2.2/$id/posts?fields=picture,full_picture
P.S. I noticed that full_picture won't always provide full size image I want. 'attachments' does
https://graph.facebook.com/v2.2/$id/posts?fields=picture,full_picture,attachments
Hum... I think I've found a solution.
In fact, in can just request
https://graph.facebook.com/me/friends?fields=id,name
According to http://developers.facebook.com/docs/reference/api/ (section "Pictures"), url of profile's photos can be built with the user id
For example, assuming user id is in $id :
"http://graph.facebook.com/$id/picture?type=square"
"http://graph.facebook.com/$id/picture?type=small"
"http://graph.facebook.com/$id/picture?type=normal"
"http://graph.facebook.com/$id/picture?type=large"
But it's not the final image URL, so if someone have a better solution, i would be glad to know :)
You can specify width & height in your request to Facebook graph API: http://graph.facebook.com/user_id/picture?width=500&height=500
You can size it as follows.
Use:
https://graph.facebook.com/USER_ID?fields=picture.type(large)
For details: https://developers.facebook.com/docs/graph-api/reference/user/picture/
From v2.7, /<picture-id>?fields=images will give you a list with different size of the images, the first element being the full size image.
I don't know of any solution for multiple images at once.
I got this error when I made a request with picture.type(full_picture):
"(#100) For field 'picture': type must be one of the following
values: small, normal, album, large, square"
When I make the request with picture.type(album) and picture.type(square), responses me with an image 50x50 pixel size.
When I make the request with picture.type(large), responses me with an image 200x200 pixel size.
When I make the request with picture.width(800), responses me with an image 477x477 pixel size.
with picture.width(250), responses 320x320.
with picture.width(50), responses 50x50.
with picture.width(100), responses 100x100.
with picture.width(150), responses 160x160.
I think that facebook gives the images which resized variously when the user first add that photo.
What I see here the API for requesting user Image does not support
resizing the image requested. It gives the nearest size of image, I think.
In pictures URL found in the Graph responses (the "http://photos-c.ak.fbcdn.net/" ones), just replace the default "_s.jpg" by "_n.jpg" (? normal size) or "_b.jpg" (? big size) or "_t.jpg" (thumbnail).
Hacakable URLs/REST API make the Web better.
rest-fb users (square image, bigger res.):
Connection myFriends = fbClient.fetchConnection("me/friends", User.class, Parameter.with("fields", "public_profile,email,first_name,last_name,gender,picture.width(100).height(100)"));
I think that as of now the only way to get large pictures of friends is to use FQL. First, you need to fetch a list of friends:
https://graph.facebook.com/me/friends
Then parse this list and extract all friends ids. When you have that, just execute the following FQL query:
SELECT id, url FROM profile_pic WHERE id IN (id1, id2) AND width=200 AND height=200
200 here is just an exemplary size, you can enter anything. You should get the following response:
{
"data": [
{
"id": ...,
"url": "https://fbcdn-profile-a.akamaihd.net/..."
},
{
"id": ...,
"url": "https://fbcdn-profile-a.akamaihd.net/..."
}
]
}
With each url being the link to a 200x200px image.
I have the same problem but i tried this one to solve my problem. it returns large image.
It is not the perfect fix but you can try this one.
https://graph.facebook.com/v2.0/OBJECT_ID/picture?access_token=XXXXX
try to change the size of the image by changing the pixel size from the url in each json object as follows :
for example I change s480x480 to be s720x720
Before :
https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xfp1/t1.0-9/q71/s480x480/10454308_773207849398282_283493808478577207_n.jpg
After :
https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xfp1/t1.0-9/q71/s720x720/10454308_773207849398282_283493808478577207_n.jpg
JS styled variant.
Just set enormous large picture width and you will get the largest variant.
FB.api(
'/' + userId,
{fields: 'picture.width(2048)'},
function (response) {
if (response && !response.error) {
console.log(response.picture.data.url);
}
}
);
You can use full_picture instead of picture key to get full size image.
Note: From Graph API v8.0 you must provide the access token for every UserID request you do.
Hitting the graph API:
https://graph.facebook.com/<user_id>/picture?height=1000&access_token=<any_of_above_token>
With firebase:
FirebaseUser user = mAuth.getCurrentUser();
String photoUrl = user.getPhotoUrl() + "/picture?height=1000&access_token=" +
loginResult.getAccessToken().getToken();
You get the token from registerCallback just like this
LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
FirebaseUser user = mAuth.getCurrentUser();
String photoUrl = user.getPhotoUrl() + "/picture?height=1000&access_token=" + loginResult.getAccessToken().getToken();
}
#Override
public void onCancel() {
Log.d("Fb on Login", "facebook:onCancel");
}
#Override
public void onError(FacebookException error) {
Log.e("Fb on Login", "facebook:onError", error);
}
});
This is what documentation says:
Beginning October 24, 2020, an access token will be required for all
UID-based queries. If you query a UID and thus must include a token:
use a User access token for Facebook Login authenticated requests
use a Page access token for page-scoped requests
use an App access token for server-side requests
use a Client access token for mobile or web client-side requests
We recommend that you only use a Client token if you are unable to use
one of the other token types.