1,5 months ago I could make requests to graph api explorer and everything was ok. Suddenly, without changing anything in the code I got this error message when I tried to access the event node of a facebook page in graph api:
Undefined index: events.
I have this code which works fine:
$request1 = new FacebookRequest($session,'GET','/'.$key.'?fields=name,cover,events');
$response1 = $request1->execute();
$graphObject1 = $response1->getGraphObject()->asArray();
$array1 = json_decode(json_encode($graphObject1),true);
$source = $array1['cover']['source'];
I can take the cover photo but when I try this :
$request2 = new FacebookRequest($session,'GET','/'.$key.'/events');
$response2 = $request2->execute();
$graphObject2 = $response2->getGraphObject()->asArray();
$array2 = json_decode(json_encode($graphObject2),true);//$key is the page id
$temp = $array2['data'];
I got this error:
Undefined index: events
please help!!
You need to make it a version request. Facebook updates it's API on a regular bases. But they let you use the old version if you make a version request. This way you do not have to worry about the API being updated.
Here is a resource from Facebook on how to go about doing that.
https://developers.facebook.com/docs/apps/versions
Related
Facebook API Broken?
Ive got this code ive been using for a while now that looks at a facebook page and reports back how many fans the page has. However over the past few days its stopped working and im now getting the following error. Can anyone shed any light on why this is happening?
Error:
Warning: file_get_contents(https://graph.facebook.com/themeparkguide?access_token=2007*********3|9b5***********fcd&fields=fan_count): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /homepages/28/d541****/htdocs/*********project/facebook_stats.php on line 4
0
Code:
<?php
function fbLikeCount($id,$appid,$appsecret){
$json_url ='https://graph.facebook.com/'.$id.'?access_token='.$appid.'|'.$appsecret.'&fields=fan_count';
$json = file_get_contents($json_url);
$json_output = json_decode($json);
//Extract the likes count from the JSON object
if($json_output->fan_count){
return $fan_count = $json_output->fan_count;
}else{
return 0;
}
}
echo fbLikeCount('coregenie','___APPID___','___APPSECRET___');
//https://stackoverflow.com/questions/37572559/facebook-graph-api-read-followers-count/42336057
?>
It works in the API Explorer: https://developers.facebook.com/tools/explorer/?method=GET&path=themeparkguide%3Ffields%3Dfan_count&version=v2.12
So i assume with some error logging, you would get the error that your App is inactive. Try with a different or new App instead. This should not be affected by the recent changes.
Side note: You should not use that script on every page load, better cache the result for some time. If a lot of users visit the page in a short time, you will hit the rate limit.
The Facebook API has changed .
The fan_count can be retrieved using an user token only after aprovement by Facebook Platform, completing the submission process .
The fan_count can be retrieved using page access tokens, to get fan count for that page .
Attention: Graph Explorer can get the page information if yours pages, so, be carefull on testing your apps, and use TEST USERS for testing insead your profile, ok ,
After test submit it for aprooval, and you be done !
I have 3 events:
https://www.facebook.com/491594114271958 (Mad Haus)
https://www.facebook.com/569226999799343 (Deuglish)
539504962802119/ (Piffle)
All are being fetched via the PHP
$config = array();
$config['appId'] = $appId;
$config['secret'] = $secret;
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
$ev = $facebook->api('/'.$id."?fields=cover,description,location,name,owner,venue",'GET');
print_r($ev);
For some reason Mad Haus and Piffle do not return venue data but Deuglish does. All events return basic data such as title, description and start time. When I run them through the Graph API explorer the venue data is returned as expected but not through the PHP API, any ideas? I can not for the life of me see the difference with these 3 events.
Thanks,
Caroline
Well, if you don't want to wait for the Facebook developers to fix the bug, you can try the same by making a simple GET request (of course along with an Access Token) to Graph API using PHP cURL. Since you are able to retrieve the venues while using the Graph API explorer, I'm pretty sure you'll be able to get them by making a simple GET request using PHP cURL.
This however involves an overhead of parsing the received JSON object and dealing with errors will be a little difficult here. But you can give it a shot.
I'm trying to get a user's credit balance with this code:
$obj = json_decode(
file_get_contents('https://api.facebook.com/method/users.getStandardinfo'.
'?uids='.$facebook_uid.'&fields=credit_balance&access_token='.
''.$access_token.'&format=json'));
I get error code 13 with this message:
The underlying FQL query made by this API call has encountered the following error: credit_balance is not a member of the user table.","request_args".
I've approved for credits in my game a lot of places and 95% sure on, that I've been accepted.
What to do?
Simon, if you have re-authenticated the user and retried then it is likely an issue on our end. Can you post your application ID and I will take a look.
I had the same problem. There are couple of things you need to do to get facebook credit balances in your app.
Get your App whitelisted by Facebook so you can call this API.
Use the code below to get the credit balances.
Facebook's own documentation didn't work either. (No surprise there) Instad I used the code below.
$accessTokenURL = 'https://graph.facebook.com/oauth/access_token&client_id=' .$app_id .'&client_secret=' .$secret .'&grant_type=client_credentials';
$accessToken = file_get_contents($accessTokenURL);
$creditsInfoURL = 'https://api.facebook.com/method/users.getStandardinfo?fields=credit_balance&format=json&uids=' .$query_uid.'&' .$accessToken;
$creditsInfo = file_get_contents($creditsInfoURL);
list($creditsArray) = json_decode($creditsInfo, true);
$fbcredbalance = 0;
if(isset($creditsArray['credit_balance'])) {
$fbcredbalance = $creditsArray['credit_balance'];
}
I have written an Application what posts Photos on a FanPage into a Specific Album long time ago.
Now I didn't used for a half year. Now I had to set up the Application again and grant the extended Permissions to the Fan Page (streamm_publish) again.
But now I've a Problem, I'm using the old REST API what now gives me the error: An unknown error ocurred with the error code 1.
Then I tried to post throught the Facebook Graph api.
I tried to make a call to the Api /pageid/albumid/photos what's not working(Unknown path components)
I tried to makea a call to /albumid_from_my_page/photos then the Photos were posted to my profile
I tried to upload it to /pageid/photos what is the same as the one above
But the code fpr the REST Api worked well, what's the problem there, and why the new Graph Api isn't working how she should?(BUG?)
To post a photo to an album, this is the code:
$post_data = array(
"message" => "My photo caption",
"source" => '#' . realpath($file)
);
$album_id = "XXXXX";
$facebook->api("/$album_id/photos", 'post', $post_data);
Now I suppose to interact with the page albums you need a page access_token added to your $post_data array, for this check this answer.
You need take ACCESS_TOKEN page...
try:
http://graph.facebook.com/me/accounts?access_token= GET THIS TOKEN USING GRAPH API... OR MAKE USING the getAccessToken()...
and will see all pages and aplications that u have, find just application for this case and COPY TOKEN... and damn!!!
It's possible to see this token thought GRAPH API EXPLORER...
regards.
I am using the following code, but it showing a 404 error
$url = "http://api.twitter.com/version/statuses/user_timeline.json";
$call = file_get_contents($url);
There's no 'version' version. The Twitter API is currently version 1, so you need http://api.twitter.com/1/statuses/user_timeline.json.
Do note that Twitter can't read your mind, so you'll need to tell Twitter which user's timeline you want to fetch... i.e. http://api.twitter.com/1/statuses/user_timeline.json?screen_name=ceejayoz