Facebook Graph API: /id/picture returns "Invalid response" - facebook

I have a Facebook application that has been retrieving pictures using the guidance found here: Using Pictures
This has been working up until recently, where now if I retrieve an item picture using the following:
/<id>/picture
I get this response:
{
"error": "Invalid response"
}
Is this a known issue? This has been working up until around this week.

Instead of picture, you should use profile_picture if you want the URL of the pic, just like-
<ID>?fields=profile_picture
Example
And if you want to use the image directly you can use:
http://graph.facebook.com/<ID>/picture
Example: http://graph.facebook.com/Shadowfax.sahil/picture

Using the /ID?fields=picture does not help when you'd like to get an arbitrarily large image. I have experienced Invalid Response when calling /ID/picture in the Graph API and found a solution that fixes it.
Try /ID/picture?redirect=false&width=800. The redirect=false option seems to fix the problem with invalid response from the API.

Related

Can't display Facebook user avatar with Facebook API and Graph

I'm working in a React-Native app, and I'm also allowing users to login using FBSDK.
There seems to be an issue at the moment when trying to get the profile picture URL.
There are also several reports of this, like this one but still, after a year doesn't seem to be solved.
Attempted many ways but none worked, it always tries to download the file, seems it's missing the mime-type according to what the browser says.
The URL it gives is the following:
https://platform-lookaside.fbsbx.com/platform/profilepic/?asid={{myfbid}}&height=50&width=50&ext=1583348357&hash=AeTnFpMVwBXgFy_J
Also tried using the graph url directly: http://graph.facebook.com/{myid}/picture
And if I add the &redirect=false, it returns a data object with the platform-lookaside URL.
Everything I try, it tries to download.
This is how I'm currently trying to get the image using Graph API.
new GraphRequestManager().addRequest(new GraphRequest(
'/me',
{
accessToken: fbToken,
parameters: {
fields: {
string: 'picture.type(large)'
}
}
},
graphRequestCallback
)).start();
It works, but the URL is the same.
Any idea on how can I solve this? I might be missing something or the bug is still happening?
If you just change the graph url (http://graph.facebook.com/{myid}/picture) from http to https, it should work for you. Not sure if that's a new fix in React Native or not, but that solved it for me.

Facebook Ads API: How can I create ads preview without create campaign first?

I check a lot of documents, and flow like that:
Submit data to create Campaign, target, and AdCreative
Use ID of AdCreative to generate preview code
Display preview code to my site (to show to my user)
But I don't want to create Campaign, Targeting, and AdCreative before preview, just submit raw data of AdCreative to get preview code.
I found that doc https://developers.facebook.com/docs/graph-api/reference/generatepreviews/, and look like they can solve my problem... But it didn't work.
My test data is: https://graph.facebook.com/v2.6/generatepreviews?ad_format=RIGHT_COLUMN_STANDARD&creative={"object_story_spec":{"link_data":{"message":"msg","link":"http://kimkha.com?1","caption":"ccccc"}},"name":"NAME 1","body":"dddddd","title":"titititit","call_to_action_type":"OPEN_LINK","object_url":"http://kimkha.com"}&access_token=<token>
And the error:
{
"error": {
"message": "(#275) Cannot determine the target object for this request. Currently supported objects include ad account, business account and associated objects.",
"type": "OAuthException",
"code": 275,
"fbtrace_id": "GeckbxpU9gr"
}
}
I ran into the same problem and got past it, despite not being able to get a fully-functioning dynamic preview working. Here are some more pointers to help save others the pain.
The url needs to include an "ad account, business account or associated objects" like the error message states. For my case I used my ad account id (https://www.facebook.com/business/help/1492627900875762). The url changed to be the following base format: https://graph.facebook.com/v2.10/act_<your-app-id>/generatepreviews
When you get the response, you need to decode the body and you can use the url directly to test. I replaced \/ with /, & with & and removed the trailing slash. After this you get a url that should give you more specific error messages
I had to also specify a "page_id" parameter that the ad will be associated with. This is a sibling of "link_data" in the sample JSON listed above.
You may get error messages telling you to change the format of certain fields.
Eventually I got the error "Preview Not Available: Unable to display a preview of this ad. (fbtrace_id: Dsfql/z/qVI)" and finally lost the will to continue. The documentation is far from easy to follow and does not have clear examples.
I'm sorry I can't give a working solution, but for my case I was evaluating this API for a non-critical piece of work and timeboxing prevented me from proceeding. Hopefully I help save some time for someone else.
I ran into this problem. The solution for me was to use my app token instead of the Graph API Explorer's token. Hope this helps!
My two cents after struggling on this issue. My request had to be formatted as follows (this is using video data, but should extend to link data):
act_{ACT_ID}/generatepreviews
?ad_format=DESKTOP_FEED_STANDARD
&creative={object_story_spec:{
page_id:<PAGE_ID>,
video_data: {
image_url: <IMAGE_URL>,
call_to_action:{
type:"SHOP_NOW",
value:{
link: <URL>
}
}
}
}}
In this case, the call_to_action has to be placed inside the video_data (or link_data) parameter and has to be formatted as an object. I did also have to change & with &, as Matt mentions.

Facebook Applinks return no applink data at all

I'm using the Facebook Graph API, Mobile hosting API to post a link with the following:
https://graph.facebook.com/{APPID}/app_link_hosts?access_token={ACCESS_TOKEN}&name=Puzzle_1420352145684&ios=[{"url":"MyAPP://playerPuzzles/1420352145684","app_store_id":{MYAPPID},"app_name":"MyAPP"}]&web={"should_fallback":false}
I get the correct result in the form of the ID of the link, with no error.
But when I query the link with
https://graph.facebook.com?ids={LINK}&access_token={ACCESS_TOKEN};
I don't get any app-link data the object is there but empty not even the name.
{"http://fb.me/777314042342441" = {
id = "http://fb.me/777314042342441";
};
}
Is there something wrong in my posting that doesn't allow the data to get posted?
Thanks for you help in advance.
It seems that the facebook documenatation is wrong. I finally found a solution using the graph explorer.
To correctly fetch the data use this style of URL.
https://graph.facebook.com/{APP-LINK-ID}?fields=ios,name,web&access_token={ACCESS_TOKEN};
Please note that you have to call out all the fields you want. The object at least for me didn't include the app_links structure like the documentation.
Here is the link to the wrong Index API
Here is the app_links object structure you can see all the fields you can fetch.
Hope this helps everyone.

Facebook photo.addtag give me an error "Invalid photo tag subject"

I've a new problem with photo tagging in facebook rest api...
I'm using photo.addTag with the correct parameter but the response give me an error "Invalid photo tag subject"
How can i fix it?
Thanks
https://api.facebook.com/method/photos.addTag?pid=100001615002070_596708&tag_uid= FRIEND_UID&x=0&y=0&owner_uid= OWNER_UID&access_token=XXXXXXXXXXXXXXX&format=json
the new graph api has a different parameter, you have to change "tag_uid" to "to", as described here:
https://developers.facebook.com/docs/reference/api/photo/
(see the section about tags)
can you present the full code of your call to the graph api? would be easier to help you then.

List of Facebook error codes

I'm looking for a list of all Facebook can return when you try to fetch infos using Graph API. Can anyone help?
Facebook returns a 400 HTTP error, and a JSON content like:
{
"error": {
"type": "OAuthException",
"message": "Invalid OAuth access token signature."
}
}
I'm searching the different returns of the same kind it is possible to get.
Facebook used to have this published somewhere, but for whatever reason it was removed. But you can find the full list here:
http://www.takwing.idv.hk/tech/fb_dev/faq/general/gen_10.html
There seems to be a list now for the errors.
I posted answer for the same question here: Facebook Graph API error code list
(I found the list here https://developers.facebook.com/docs/graph-api/using-graph-api/error-handling)
In case Takwing's copy ever comes down, here's another copy: http://fbdevwiki.com/wiki/Error_codes
These codes were primarily for the REST API, but they do also come up with the Graph API. Some of the Graph API calls have underlying FQL calls that return the FQL error codes. And the direct FQL queries are still part of the currently accepted API.
Update: I'm trying to keep this list up-to-date. Please feel free to make changes as you encounter new errors.
I am trying to keep an updated list of error codes based on previous outdated information.
You can find the repo here http://github.com/phwd/fbec and it has been updated with Test User and Credit Error codes from the Facebook Documentation.
Currently looking for the constant name for "Error Code 2500" and some error descriptions may have changed. I hope to keep on top of this.
There is an official error code page, now:
https://developers.facebook.com/docs/marketing-api/error-reference/
It still doesn't look comprehensive...