Facebook 尝试检查用户是否安装了我的应用程序。但获取未捕获的OAutheException(访问令牌)
我正在尝试检查用户是否安装了我的应用程序。流程如下Facebook 尝试检查用户是否安装了我的应用程序。但获取未捕获的OAutheException(访问令牌),facebook,facebook-graph-api,oauth,access-token,Facebook,Facebook Graph Api,Oauth,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. 我似乎没有访问令牌来检查权限。它显示以下错误
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\u令牌,以查看是否收到了访问令牌。是的,我确实得到了密码。但不知怎的,我还是犯了错误
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\u令牌
传递到api()
函数中。尝试如下方式调用API:
$permissions=$facebook->api(“/me/permissions”)代码>
如果这不起作用,您可能需要将Facebook SDK升级到最新版本。此外,在查询API以获取用户权限之前,还需要检查access\u令牌
是否实际返回。如果用户尚未登录并已批准应用程序,则您的代码将失败。将代码更改为类似以下内容:
$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"
}
}
谢谢你的回复。我想我正在使用最新的SDK。但让我先试试你的代码,我会让你不断更新。我曾经尝试不将$access\u令牌传递到api中。那不起作用,所以我试着把它包括在我的报告中。