file_get_contents() returns "failed to open stream" when used with Facebook access_token flow

Posted by TMC on Stack Overflow See other posts from Stack Overflow or by TMC
Published on 2010-05-11T08:26:31Z Indexed on 2010/05/11 8:34 UTC
Read the original article Hit count: 499

Filed under:
|

file_get_contents() is returning "failed to open stream" when I call it on a Facebook oAuth access_token URL.

Warning: file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=XXXXX&redirect_uri=http://mydomain.com/fb/callback3.php&client_secret=xxxx&code=YYYY) [function.file-get-contents]: failed to open stream: No error in E:\\htdocs\fb\callback3.php on line 5

(I have removed ClientID, clientSecret and the oAuth Code).

If I try to manually hit the Facebook access_token URL that my code is attempting to fetch, I get an actual payload returned in the browser:

access_token=XYZ&expires=6508

(where XYZ is the access token)

So for some reason, there is a problem with the access_token URL specifically when used with file_get_contents().

At first, I thought it was a security issue with my webhoster, but I have verified with phpinfo() that allow url open is indeed allowed. I have also tried this code and verified it works:

$foo = file_get_contents('http://google.com');
echo $foo

Anyone have any ideas why file_get_contents() is failing with the Facebook access_token URL?

© Stack Overflow or respective owner

Related posts about php5

Related posts about facebook-api