English 中文(简体)
尝试检查用户是否安装了我的应用程序 。 但获取 Unchabt OAuth Exception( 访问标记)
原标题:Try to check whether user has installed my app or not. But get Uncaught OAuthException (access token)

我试图检查用户是否安装了我的应用程序。 流程如下 :

    1. Check whether has installed or authorize my app 
    2. If yes, then direct user to play my app directly
       If no, then direct user to see welcoming page to read term of use and privacy.

我似乎没有访问符号来检查权限。 它显示在下面错误 。

    Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user

我的代码是这样的。 我还会回声 $access_token 来查看我是否收到了存取凭证 。 是的, 我确实得到了代码, 但不知怎么我还是得到了错误 。

require_once( src/facebook.php );

$app_id = "APP_ID";
$app_secret = "APP_secret";

// Init facebook api.
$facebook = new Facebook(array(
     appId  => $app_id,
     secret  => $app_secret,
     cookie  => false,
));

$access_token = $facebook->getAccessToken();
//echo $access_token;

$permissions = $facebook->api("/me/permissions", $access_token);
if( array_key_exists( publish_stream , $permissions[ data ][0]) ) {
   // Permission is granted!
   echo "App has been installed";
   //then redirect to content page
} else {
   echo "App has not been installed";
   //then redirect user to welcoming page and let user read "term of use" and "privasy"
}

请救救我

最佳回答

您不需要在 $access_token 中通过 api () 函数。 请尝试这样调用 API :

$permissions = $facebook- gt; api ("/me/permissions"); = $facebook- & gt; api ("/me/permissions");

如果这不起作用, 您可能需要将 Facebook SDK 升级为最新版本。 另外, 值得检查的是, 在查询 API 权限之前, 是否实际返回了 < code> access_ token 。 如果用户尚未登录并批准了该应用程序, 您的代码将会失效 。 将代码更改为类似 :

$access_token = $facebook->getAccessToken();

if ( $access_token ) {
    $permissions = $facebook->api( "/me/permissions" );
    if( array_key_exists( publish_stream , $permissions[ data ][0]) ) {
       // Permission is granted!
       echo "App has been installed";
       //then redirect to content page
    } else {
       echo "App has not been installed";
       //then redirect user to welcoming page and let user read "term of use" and "privasy"
    }
}
问题回答

暂无回答




相关问题
Facebook Connect login dialog not working

I am using Facebook Connect for iPhone and following the official instructions. I use the following code to display the login dialog: FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:...

Facebook App Profile Tab is Empty ... No Content Displayed?

I can view my application via the http://apps.facebook.com/myapplication/ link and the content shows up correctly. I also added the application as a tab to a facebook page. However, when viewing the ...

Facebook Platform error: "Object cannot be liked"

I m working on a Facebook Application that generates wall posts. In testing these posts, I ve discovered that the Facebook Platform action of "liking" a post is failing. The specific error message ...

how to call showPermissionsDialog() in php (facebook api)?

I was reading over the documentation yet I could not figure out how to call Facebook.showPermissionsDialog() in php include_once ./facebook-platform/php/facebook.php ; $facebook = new Facebook(my ...

Facebook connect

If I plug in the facebook connect into my website, How can I prevent double signups? Lets say I have a user that s already signed up to my site but he clicked the connect with facebook, is there a ...

热门标签