Chibuzo
Chibuzo

Reputation: 6117

Error while attempting to retrieve data from facebook social graph API

I get the error

Warning: file_get_contents(https://graph.facebook.com/me?fields=id,name,picture) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /home/schoolda/public_html/fblogin.php on line 36

while trying to retrieve user data from facebook graph API. I've successfully authenticated and authorized my app but I don't know how to retrieve the granted data. Thanks for any suggestion.

Upvotes: 0

Views: 824

Answers (2)

Robin Castlin
Robin Castlin

Reputation: 10996

Apart from auth token, you may want to try to add error_reporting to the file_get_contents:

$val = stream_context_create(array('error_reporting' => TRUE));

and use $val in the 3rd paramter of file_get_contents.

Why? Because then you can echo out the result and see why Facebook says "no". When an error occurs with the api, Facebook sends an error answer back to your server.
file_get_contents then by default asumes that your request didn't work at all.

Upvotes: 2

Ben
Ben

Reputation: 2651

You need to include your auth token in your api request.

try:

file_get_contents(https://graph.facebook.com/me?fields=id,name,picture&access_token=FACEBOOK_ACCESS_TOKEN)

Upvotes: 1

Related Questions