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.
Related
I'm trying to get recent images from an Instagram API account, using the following code:
function getRecentMedia( $UserId, $Token ) {
$url = 'https://api.instagram.com/v1/users/'
. $UserId
. '/media/recent/?access_token='
. $Token
;
return $this->curlGet( $url );
}
curlGet simply does a curlRequest and returns the results. This request returns recent images, so long as I pass the userId and a token for the account I'm trying to access, but all the images are square, with white "letterboxing" at either the top and bottom or on the left and right. So, a typical post will include a 150x150 image, a 320x320, and a 640x640 image.
If I understand http://developers.instagram.com/post/128288227716/api-migration-for-landscape-and-portrait-formats , this feed should just return the images in their original orientation, but it isn't. The "Non Square Media" checkbox is checked on the developer page. Does anyone have any idea why the images would still be resized into perfect squares.
Does
i'm using this api:
public function getUserMedia($id = 'self', $limit = 0) {
return $this->_makeCall('users/'.$id.'/media/recent', true, array('count' => $limit));
}
to fetch the photo of a user logged in my site using php
it works, and all other api works.
the problem is that i want to retrieve ALL the photo of a user (such as printstagr.am).
i've searched in the api but without success: it seems that you can take the recents or the populars, but the site mentioned above takes all. any idea?
thanks!
Not sure what the max count is (saw someone mention 20 was the max on another question, but can't find any limit in the docs from a quick scan), but essentially what you have to do is request as many as possible, then follow the pagination links to collect more.
So from the api docs they provide this:
{
...
"pagination": {
"next_url": "https://api.instagram.com/v1/tags/puppy/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d&max_id=13872296",
"next_max_id": "13872296"
}
}
Your application needs to store the objects from the request (i.e. an array), then fire a new request to the "next_url", put those objects into the same store (i.e. array), then follow the link again, until you reach the end or until you get enough to satisfy your needs.
I need a way to display videos from a specific channel on a page using PHP.
I have authenticated my app and I can use some methods using the advanced API. I am using the official vimeo PHP library to connect.
Below is what I am trying to do and when I dump the array I do not get anything. I can get info back from using get videos from the entire account method.
require_once('/url/vimeo/vimeo.php');
$vimeo = new phpVimeo('number', 'number');
$vimeo->setToken('number','numbers');
$videos = $vimeo->call('vimeo.channels.getVideos', array('ACCOUNT' => 'NAME'));
If I put the channel name where ACCOUNT is I will get an invalid signature error.
Is it worth using something like simple HTML parser for PHP and doing it that or worth sticking with the advanced API?
I would highly advise using the advanced api. If you parse the html, it will break any time vimeo changes their channel pages. Additionally, channels have more than one layout
eg: vimeohq and nicetype
The second parameter of the "call" function should be any querystring parameters the api method requires.
In the case of "vimeo.channels.getVideos" you can provide
channel_id
user_id
page
per_page
summary_response
full_response.
To experiment with the getVideos method, you can use the playground.
So in the end, I believe you want the function to look like this..
$videos = $vimeo->call('vimeo.channels.getVideos', array('channel_id' => 'NAME'));
where NAME is either the channel id, or the channel name (the channel name matches the url slug, so for example "nicetype" not "nice type"
I am trying to upload a photo from my server to an album on my page.
I have the following code to send the photo:
$argsFeed = array( 'source' => '#' .$FILE_PATH,
'published' => true,
'message' => $caption);
try {
$imageId2 = $facebook->api('/'.$ALBUM_ID.'/photos', 'post', $argsFeed);
} catch(FacebookApiException $e) {
$result['status'] = "error";
$result ['message'] = $result ['message'] . ' ||| error posting photo to page 164264490295119. facebook says: <BR/>' . json_encode($e->getResult());
}
I have the following permissions:
publish_stream,user_photos,manage_pages
I always get success for the api-call, with a photo id, but the photo doesn't go anywhere.
The exact same photo was posted to my (the user's) wall as well, so the photo can't be the problem.
my guess is that it does get posted somewhere, since there's no exception, only I don't know where it's posted.
anyone has a clue?
I get photo-id's like this one:
10151091881973938,633203937_10151091735008938
but I don't know what to do with them - how do I look them up in the graph?
It's difficult to diagnose this without some more context. Is $facebook->api performing a POST?
However, the fact that your retrieving photo-ids without image extensions leads me to believe that your problem could be that the image extension isn't making its way to the Facebook POST; thus you can't display an image that doesn't have a .jpg or .png extension. This would explain why it accepts the file as it is of type=image
I get photo-id's like this one: 10151091881973938,633203937_10151091735008938 but I don't know what to do with them - how do I look them up in the graph?
The first part before the comma is definitely your photo’s id in the Graph.
That’s your photo object on the Graph:
https://developers.facebook.com/tools/explorer?method=GET&path=10151091881973938
That’s one of the actual image URLs on Facebooks CDN:
https://fbcdn-photos-a.akamaihd.net/hphotos-ak-snc6/283597_10151091881973938_1730322674_a.jpg
And that’s the display URL of your photo on facebook.com displaying it as one of your photos in your album:
https://www.facebook.com/photo.php?fbid=10151091881973938&set=p.10151091881973938&type=1
The second part, 633203937_10151091735008938 is obviously your user id combined with your photo’s id. Did you get them all as one string, as you posted them, photo_id comma userid underscore photo_id, or did you just post them as this?
Normally I would expect just the photo id to be returned from a successful photo post through the API.
I just saw it is working for others. I dont know whether it is working to everyone, or just working to few people.
My coding is not suddenly working for the last two days.
It is PHP graph api
$facebook->api('/me/photos?access_token='.$access_token, 'post', $arguments);
This is how it is uploaded.
Nothing was changed. It was working fine. It is all not working for the last two days.
Error is
OAuthException: (#100) Cannot specify user tags without a place tag
$arguments is an array which contains the image, tags (which is also an array) and message
I have the same problem! The same code, but don't work for the past 24 hours.
I use graph api via Action Script. I HTTP POST a request with a parameter Object, which contains tag_uid, x, and y. Bad request just as following:
{
"error": {
"message": "(#100) Cannot specify user tags without a place tag",
"type": "OAuthException",
"code": 100
}
}
The API didn't recognize the x parameter and y parameters. So, I tried to use the api method /photoID/tags. This way works without specifying the x and y parameters, if you do specify them, it won't work.
https://developers.facebook.com/docs/reference/api/user/#posts
tags
Comma-separated list of Facebook IDs of people tagged in this Post. For example: 1207059,701732. This field is returned as the
with_tags field when the Post is read.
NOTE: You cannot specify this field without also specifying a place.
So I think you should also specify the place (page Id of the location associated with the post) in order to put tags.
You have to add place value to the params. place value is page_id in facebook.
sample actionscript code is as following
tagArr = '[{"tag_uid":"' + String(userVO.uid) + '", "x":"1", "y":"1"}]';
var params:Object = {access_token:userVO.accessToken, place:"123456789", tags:tagArr, image:bitmap, message:msg, fileName:'FILE_NAME'};
Facebook.api('/'+userVO.uid+'/photos', onCompleteHandler, params);