I'm developing a small facebook app but having problems with be able to grant extended permissions, i want to grant the following permissions:
read_stream & publish_stream & offline_access
However i want to do this without using FBML, any ideas how you can do this using the new PHP SDK on git hub: link (http://github.com/facebook/php-sdk/raw/master/src/facebook.php)
I would like to be able to login and grant these permissions at the same time.
Anybody know if开发者_如何学C this is possible?
Don't even need the SDK. This is pretty much a copy'n'paste from https://developers.facebook.com/docs/authentication/ with a couple of tweaks (their code was tripping a PHP error for me when the $_REQUEST["code"] wasn't set on the first pass), and with the appropriate permissions added to the initial authentication request.
$app_id = 'YOUR_APP_ID';
$app_secret = "YOUR_APP_SECRET";
$my_url = "TARGET_URL_ONCE_PERMISSION_IS_GIVEN";
$code = isset($_REQUEST["code"] ) ? $_REQUEST["code"] : false;
if(!$code) {
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&scope=publish_stream,offline_access&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
. $app_secret . "&code=" . $code;
$access_token = file_get_contents($token_url);
$graph_url = "https://graph.facebook.com/me?" . $access_token;
$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name);
精彩评论