Facebook Graph API - retrieve photos from album INCLUDING source (original photo url) - facebook

I retrieve the list of photos in an album like following:
String url =
"https://graph.facebook.com/v2.5/" +
albumId +
"/photos?fields=created_time,height,id,images,picture,name,updated_time,width";
There seems to be no field source in the album request... The picture array contains a lot of image urls, but it seems that it does NOT contain the original url. I see images where I can't find the original image in the picture array...
So the only solution I found is to make a request for every image like following:
String url = "https://graph.facebook.com/v2.5/" + id + "?fields=source";
And extracting the source value from this answer.
Is there any better approach? I know width, height and many urls, but I need the original image url as well... It's somehow weird to make a request for every single image just for that information...

You can get all this data in one go, by using the field expansion syntax:
/album-id?fields=photos{created_time,height,id,images,picture,name,updated_time,width,source}

Related

We can not retrieve image url for the product from 3dcart.com

we are using the following Rest API with default values for limit and offset.
https://apirest.3dcart.com/Help/Api/GET-3dCartWebAPI-v1-Products-catalogid-Images_limit_offset
We are invoking on a standard out of the box 3d cart sample store with sample products. We can verify that the product with the correct catalogid has images.
The response we got is http 200 code and an empty array [].
We tried different values for limit and offset.
Could you advise? Did we use the wrong api?
Thanks.
The article
https://apirest.3dcart.com/Help/Api/GET-3dCartWebAPI-v1-Products-catalogid-Images_limit_offset
is wrong. Now we need use the url
http://apirest.3dcart.com/3dCartWebAPI/v1/Products?catalogid=XXXX
for images.
You would get a collection with the image information as follows:
"MainImageFile":"assets/images/generic/tshirt.jpg",
"MainImageCaption":"",
"ThumbnailFile":"assets/images/generic/tshirt_thumbnail.jpg",
"MediaFile":"",
"AdditionalImageFile2":"",
"AdditionalImageCaption2":"",
"AdditionalImageFile3":"",
"AdditionalImageCaption3":"",
"AdditionalImageFile4":"",
"AdditionalImageCaption4":"",
"ImageGalleryList":
Thanks.

Manage Titles when Uploading Multiple Images

It would be great if we could manage the titles of each image that we upload when uploading multiple images. This way I could select each image that I want to upload, title them, then hit the upload button. Right now one must either upload one by one or have all the selected images have the same title.
Kinda like Facebook or Panoramio where it's easy to manage the titles of the images before uploading.
This isn't natively supported in Fine Uploader at the moment, but I've opened up a feature request and tentatively scheduled it for the 3.7 milestone. In the meantime, you can certainly provide your own UI elements to allow users to provide alternate names for each upload-able item and pass these new names as a parameter. Server-side, you would have to parse this parameter and associate it with the uploaded item. Fine Uploader will have to adopt a parameter name that contains the user-supplied alternate filename anyway (and the server will have to be aware of this convention and parse this parameter), since we won't be able to change the value file input field sent along with the multipart encoded request.
use this:
var uploader = $('.uploader'),
titleBox = $('input[type=text]');
uploader.fineUploader({
request: {
endpoint: 'path/to/url'
},
formatFileName: function (name) {
var title = titleBox.val() + ' - ' + name + '';
titleBox.val('');
return title;
},
});
uploader.on('submit', function (event, id, name) {
uploader.fineUploader('setParams', {title: titleBox.val()}, id);
});

graph API large post thumbnail

I'm working with the graph api and I ran into a problem: I get all the feeds from my page using: https://graph.facebook.com/page_ID/posts and then I display them in a nice way that requires larger thumbnails than the really small ones returned in data[i].picture .
I know it's possible for profile pictures... I've been reading the doc quite a bit and looking around and now I've got no clues... Have I missed something?
You can try doing FQL query to get the posts like so:
SELECT post_id, message, permalink, attachment, actor_id, created_time FROM stream WHERE source_id = PAGE_ID AND message != ""
If that still brings the same image size you can use this hack:
Disclaimer:
This is not a good method as Facebook may change the image path anytime.
That been said, for every image with this file name format:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_s.jpg
You can change the letter "s" just before the ".jpg" to "n" and get a bigger version like so:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_n.jpg
Changing it to "q" will give you an image with a width of no more then 180 pixels
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_q.jpg

From CMIS how do I get the thumbnail placeholder for Alfresco?

I understand that the following URL will give me the thumbnail of a document or the placeholder image, if there isn't a thumbnail. This works because of the ph=true at the end.
http://cms.mydomain.com:8080/share/proxy/alfresco/api/node/workspace/SpacesStore/" + childId + "/content/thumbnails/doclib?ph=true
I have also found that the following server side code will get me the ContentStream of the thumbnail image.
OperationContext context = session.createOperationContext();
context.setRenditionFilterString("cmis:thumbnail");
CmisObject doc = session.getObject(id, context);
List<Rendition> renditions = doc.getRenditions();
if (renditions.size() > 0) {
Rendition rend = renditions.get(0);
cs = rend.getContentStream();
}
The problem with this is it does not return the placeholder image if there isn't a thumbnail, like the first URL.
For the server side how would I retrieve the appropriate placeholder image when there isn't a thumbnail? For example for docx and xlsx files.
Thanks,
Jon
I think in this case the most effective way to retrieve thumbnails (doclib or a placeholder) is to call directly the REST Alfresco Service.
I'm not 100% sure but CMIS rendition response from an Alfresco Server contains only existing renditions. There's no placeholder provided in CMIS renditions part like the one provided by the Alfresco REST url.
The key here is in if (renditions.size() > 0) -> this is exactly what the webscript does.
But what the REST webscript also does is to ad an else -> so if there aren't renditions so far, it fill determine mimetype and fetch the corresponding placeholder.
You should do the same in your code to make it fetch placeholder -> add an else and then find the placeholder for that image.

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.