4

「現在のユーザーに関する情報を照会するには、アクティブなアクセストークンを使用する必要があります」というエラーが表示されます。たくさんの記事やアイデアがあるようですが、非常に混乱していて、状況も変化しているようです。多くの人がオフラインアクセスを使用すると言いますが、それはなくなるようです。私はこの記事を見つけました。

PHP SDKを使用した例はありますか?

以下のようなことをしてみましたが、うまくいかないようです。$FBuserまだゼロです:

$token_url =    "https://graph.facebook.com/oauth/access_token?" .
                            "client_id=" . FB_APP_ID .
                            "&client_secret=" . FB_APP_SECRET .
                            "&grant_type=client_credentials";
list($name, $ACCESS_TOKEN) = explode("=", file_get_contents($token_url) );
$facebook->setAccessToken(ACCESS_TOKEN);
$FBuser = $facebook->getUser();
4

1 に答える 1

0

これを試してください(このリンクに従ってスコープパラメータを変更してください):

// Checks if the user granted the access (after the redirection bellow)
$user = $facebook->getUser();
if(!$user) {
    // If not: Retrieves the login url in order to redirect the user
    $url = $facebook->getLoginUrl(array('scope' => 'user_about_me', 'grant_type' => 'client_credentials'));
    // redirect here (after accepting the user will be redirect back to the same url. In other words this script, that will check again if the user is authenticated)
} else {
    // Now the user is authenticated
    $user_data  = $facebook->api('/me');
    $user_token = $facebook->getAccessToken();
    // Saves the access token
}
于 2012-09-08T21:31:28.947 に答える