Facebook graph api function - empty response - facebook

im currently working on facebook integration into my mobile AS3 game. I'am downloading friends pictures, which works just fine and is not currently an issue. Problem is, i am trying to detect, if user has silhouette (default) picture or his own (is_silhouette property);
Here goes code:
(response[i].id) is valid user id which i have got from previous api comunication
...
HasDefault(response[i].id);
...
private function HasDefault(uid:int):void{
FacebookMobile.api("/"+uid+"/picture", callbackX);
}
private function callbackX(response:Object,fail:Object):void{
if (response != null){
trace(response.url);
trace(response.is_silhouette);
}else{
trace("here goes nothing...");
}
first things first...this code above has 2 issues. First problem is, unless i use absolute URL, facebook does not respond, so API method has actually look like this:
FacebookMobile.api("https://graph.facebook.com/"+uid+"/picture", callbackX);
i dont know why i have to use absolute url here, because anywhere else id/function is good enough...but that is not still main problem.
If i use absolute URL i do get valid response from facebook but according to this https://developers.facebook.com/docs/reference/api/using-pictures/ i should get response.url and response.is_silhouette in my response object. i however recieve only empty response object...I'am starting to be realy desperate.
In addition, i have tried to paste THE SAME request into the https://developers.facebook.com/tools/explorer explorer and surprise surprise...it returns
{
"data": {
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc1/somenumbers.jpg",
"is_silhouette": false
}
}
...which is exactly what i need...but within the application i get only empty response object...

I do not know what you line "FacebookMobile.api("https://graph.facebook.com/"+uid+"/picture", callbackX);" does.
But whatever library that is, stop using it, because its not letting you specify the call you want to make. You can just call the graph api calls yourself using a URLLoader.
So here is the magical thing that is going wrong: You need to be able to append an extra variable when you request the picture: "?redirect=false"
This tells facebook to give you a json response. If you do not have that variable, you will get a redirect to the actual image, which is usually what a person wants anyway.
To see how that works, test out the two links below, one with redirect=false - which you want. and One with it set to true - which you do not.
https://graph.facebook.com/shaverm/picture?redirect=false
https://graph.facebook.com/shaverm/picture?redirect=true
I am pretty sure what is happening is that you are getting the image back instead of the json response describing the image.

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 until empty results

Anybody knows why i get no results back when i add the untill parameter in facebook?
Requested url: https://graph.facebook.com/FBID/home?limit=25&until=1388688636
How do i replicate this:
Go to: https://developers.facebook.com/tools/explorer
Execute the above url (FBID/home?limit=25&until=1388688636)
In the returned results go to the bottom and click the link that got the json key: "next" (looks like: "next": "https://graph.facebook.com/FBID/home?limit=25&until=1388688639")
The returned result is:
{
"data": [
]
}
i searched for ages about this problem and could not find it, the only thing i can come up with is that Facebook only returns posts since the permission accept for the Access Token, another cause could be that Facebook is broken.
This is standard (albeit undocumented) behavior. The empty data array shows up when you try to access an object that has its privacy settings configured to not let third party apps read it, and it's also what's being displayed after you've reached the end of all public records of the current user.
You just have to deal with it. Keep looping over the next result while data != empty is true.
Update: This could also be related to an open issue Facebook is aware about, namely broken pagination. The problem seems to be "dead ends". You can read more about it here and try fiddling around with the timestamp and limit parameters of the request.

POST request from iPhone to Django

I'm trying to send a POST request from iPhone to Django, but for some reason I can't. The request is sent, but the server doesn't receive it properly.
What is the regular expression that accepts POST? In my case, I use this one: /messages/a/s=person1&r=person2&c=hello/.
How do I retrieve the POST arguments in the Django view? request.POST['s'] should work?
Thanks.
POST parameters are not part of the URL, so your regex should simply detail the main part of the url you want to receive it on. To take your example, change it to /messages/a/. Then, in your "messages" app, have a view/function called a: that one will be reached on receiving any POST (or GET, which you're currently (almost) depicting in your url) to that location.
The arguments can then indeed be retrieved using request.POST['keyname']. To make things more convenient, supply a default value when getting the data so you need less error checking: request.POST.get('keyname', None). This will get the value of keyname when available, or None otherwise.
The posting itself... depends on more code then you're currently showing. Can't say anything about that with your current question.
That URL you've pasted in will pass the data through the request.GET dictionary. If you want to change your iPhone app to POST data, you'll have to share your code.

Graph API - /apprequests seems to return an empty JSON array every time

When I use
https://graph.facebook.com/(userid goes here)/apprequests?access_token=(user access_token goes here)
it returns an empty JSON array like so:
{
"data": [
]
}
Even though there ARE app requests.
These people were having the same problem, but didn't get their question answered either:
http://forum.developers.facebook.net/viewtopic.php?id=106693
http://forum.developers.facebook.net/viewtopic.php?id=88253
What am I doing wrong?
I tried POSTing and GETing requests with the Graph API Explorer, and THEY don't return an empty JSON array (however they only return the app requests POSTed by Graph API Explorer, not the requests for my app....I imagine this is to be expected however). Could this have something to do with my app being in sandbox mode? Does /apprequests work for anyone else's sandboxed app?
A few weeks back (around mid-september 2011), it was possible to get the requests with https://graph.facebook.com/me/apprequests?access_token={user_access_token}.
It does not seem possible today anymore. This call returns an empty data structure now.
Instead, calling https://graph.facebook.com/{user_id}/apprequests?access_token={app_access_token} does seem to work.
apprequests connection expect an app access token.