Reputation: 877
I'm trying to write a small application which can read the public events of a Facebook page. So I don't need a specific user access_token, this would be too much work. I wrote a small script, which should get the access_token, but it doesn't :(
<?php
$url= "https://graph.facebook.com/oauth/access_token?type=client_cred& client_id=my_client_id&client_secret=my_client secret";
$access_token = file_get_contents($url);
$access_token = substr($access_token,strpos($access_token,"=")+1);
print access_token;
}
?>
if i open the url in my browser, I get an access_token, but this doesn't work :(
Upvotes: 0
Views: 142
Reputation: 1016
You can get a app_access_token this way:
$app_access_token = file_get_contents('https://graph.facebook.com/oauth/access_token?type=client_cred&client_id='.$app_id.'&client_secret='.$secret);
More info here: https://developers.facebook.com/docs/technical-guides/opengraph/publishing-with-app-token/
Upvotes: 0
Reputation: 6887
Check this out:
Hope that helps.
Resources here
How-To: Publishing With an App Token here
Upvotes: 1
Reputation: 8411
Facebook needs a browser to be able to identify the user. You cannot do it using file_get_contents.
You should redirect the url and on the landing page get the access_token.
I have a small example on my blog on how to do it. See here
Upvotes: 0