Facebook graph how to set parameters for picture? - facebook

I want to get user picture URL, but instead i get image download. In facebook developer guide It says to set redirect parameter to 0 but i don't know how to set parameters in graph, i tried it in JavaScript to but i still get picture downloaded not the URL any example, how to set parameters?
Here is what i tried:
/me?fields=id,name,picture?redirect=0
It returns syntax error.
The simple request returns image download
me?fields=id,name,picture
This is the example result:
"picture": {
"data": {
"height": 50,
"is_silhouette": false,
"url": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=3008732859171455&height=50&width=50&ext=1587125741&hash=AeSgpchLcdbLL1Mt",
"width": 50
}
}

/me/picture would be the correct endpoint, or /me/picture?redirect=false if you do not want to redirect.
Source: https://developers.facebook.com/docs/graph-api/reference/user/picture/

Related

Get Facebook Post images from Facebook Graph API v2.6

I am trying to update a client's code which pulled user's images from Facebook graph API.
I would like to pull the all the items from '/me/feed' if possible, but reading the SDK docs it looks like the feed is separate from the photos now.
The original client used v2.2 and would return a property images containing an array of images that were tied to the post.
"images": [
{
"height": 960,
"source": "https://scontent.xx...",
"width": 720
},
{
"height": 800,
"source": "https://scontent.xx...",
"width": 600
},
...
]
With v2.6 it seems the most I can get is a cover photo using full_picture as a field. '/me/feed?fields=id,message,full_picture,created_time' but this neglects the four other images on the post. There is a separate photos edge but it doesn't appear to have any way to just get the images for a specific post.
I would appreciate any suggestions on how to go about getting all feed items and their corresponding images. Thank you.
You can get the same images by doing another query on the object_id. NOTE: This is different then the actual id, which is what I was searching on before
From /me/feed?fields=id,object_id
From /{object_id}?fields=images

Get scraped data from facebook graph api using url reliably

My app needs to get data facebook scrapes from URLs. Up until now we were getting it using
POST /?id={object-instance-id or object-url}&scrape=true
Which is detailed in updating object section in https://developers.facebook.com/docs/sharing/opengraph/using-objects
For example
POST /?id=http://google.com
{
"url": "http://www.google.com/",
"type": "website",
"title": "Google",
"image": [
{
"url": "http://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png"
}
],
"description": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.",
"updated_time": "2015-10-06T11:34:58+0000",
"id": "381702034999"
}
Notice image section.
Unfortunately if og tags are configured wrongly on the server
POST /?id=http://some.page.with.bad.tags.com
{
"error": {
"message": "Invalid parameter",
"type": "FacebookApiException",
"code": 100,
"error_subcode": 1611016,
"is_transient": false,
"error_user_title": "Object Invalid Value",
"error_user_msg": "Object at URL 'http://some.page.with.bad.tags' of type '' is invalid because the given value '/some-bad-value' for property 'og:url' could not be parsed as type 'url'.",
"fbtrace_id": "abcabcabc"
}
}
Which returns nothing interesting.
Attempt to GET the url returns this:
{
"og_object": {
"id": "381702034999",
"description": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.",
"title": "Google",
"type": "website",
"updated_time": "2015-10-06T11:40:04+0000",
"url": "http://www.google.com/"
},
"share": {
"comment_count": 2,
"share_count": 13494003
},
"id": "http://www.google.com"
}
Which misses image section. I cannot find in the documentation any way to retrieve result with images without using POST /?id={url}, but that fails on any errors in og tags.
GET /{ObjectId}
returns only type and created_time
Entering the same broken link in https://developers.facebook.com/tools/debug/ results in page which contains image, description, title and captions for the page. Which I need. So it means facebook stores them, even though page has wrong tags, but I need a way to fetch them. Unfortunatelly I cannot provide link for broken url due to NDA, and I couldn't find other page with broken tags.
If the page contains invalid Open Graph markup this seems expected, also do not confuse the Graph API with some sort of datasource or a scraping service you can utilize to generate the preview for web content.
If Facebook , for whatever reason, can't parse the Open Graph tags of a URL it will try to make a good guess based on the content of the page (large junks of text, images it finds, title tags etc.) to build the preview so you might get some sort of data back from GET /{object-id} which can just be a guess instead of actual og:.. data.
In case you really need a more or less failsafe solution, you could build your own scraper that looks for Open Graph tags.

Get facebook id from url (?ids=url) some url are not working

Get facebook id from url (?ids=url) by fb graph some url are not working.
For example;
https://graph.facebook.com/?ids=https://www.facebook.com/groups/Happypattaya
The link above work fine, so I got this json (it's right).
{
"https://www.facebook.com/groups/Happypattaya": {
"id": "589515601153720",
"created_time": "2014-10-09T17:16:29+0000",
"is_scraped": false,
"type": "website",
"updated_time": "2014-10-09T17:16:29+0000",
"url": "https://www.facebook.com/groups/Happypattaya"
}
}
But
https://www.facebook.com/groups/663908986989589
and other links, as I noticed it was a numeric, I can use "preg_match" to get it if find an integer ,but I really want to grab id from fb graph anyway.
You should always add a valid access_token to any graph api request.
e.g.
https://graph.facebook.com/?ids=https://www.facebook.com/groups/Happypattaya&access_token=CAACXXXXX

Is it possible to get default Facebook Group profile pictures?

According to the officlal Facebook document, it seems that Facebook Graph API can treat Facebook Group profile pictures. However, the picture link provided at Connections section on the document doesn't return the proper image. The URL redirects to /images/icons/group-types/large/default.png, which is apparently a path for default profile picture, but it actually returns JSON that has data like this:
{
"error": {
"message": "Unknown path components: /icons/group-types/large/default.png",
"type": "OAuthException",
"code": 2500
}
}
Is this a bug of Facebook? Are there any ideas to avoid this?
Thanks in advance!
Looks like a bug, to workaround it, get the image as a String instead of a HTTP redirect:
https://graph.facebook.com/195466193802264?fields=picture
The Response is:
"picture": "/images/icons/group-types/large/default.png"
parse that, and if you get back a relative URL, prepend it with http://www.facebok.com
In this specific case, it works: Link here
In the meantime, you should File a bug report and get this updated in the API

Set Size of SWF posted to Facebook with Feed Dialog

Is there a way to set the dimensions of a swf posted to Facebook using the feed dialog, either javascript or direct url method?
https://developers.facebook.com/docs/reference/dialogs/feed/
I'm not 100% certain that this works anymore as I've tried to add this with the Feed dialog as opposed to the sharer and it seemed to have no effect at all. It may have been replaced by the source parameter in the newer feed dialog API (which I don't think you can define a width/height for. Please correct me if I'm wrong) ..
but,
take a look at media attachments in the stream attachment guide:
https://developers.facebook.com/docs/guides/attachments/
you would pass in a JSON encoded object as the media URL param.
{"media": [{
"type": "flash",
"swfsrc": "http://www.mapsofwar.com/photos/EMPIRE17.swf",
"imgsrc": "http://icanhascheezburger.files.wordpress.com/2009/04/funny-pictures-hairless-cat-phones-home.jpg",
"width": "80",
"height": "60",
"expanded_width": "160",
"expanded_height": "120"
}]}