我的应用程序停止转发到Facebook进行身份验证,并询问除具有开发者访问权限的帐户以外的所有帐户的权限。这很奇怪,因为该应用程序已经运行了多年。我的应用程序显示为实时而不是在沙箱中,但是非开发人员帐户不会去Facebook寻求权限。
require_once('src/Facebook/autoload.php');
$fb = new \Facebook\Facebook([
'app_id' => $options->fb_app_id, // Replace {app-id} with your app id
'app_secret' => $options->fb_app_secret,
'default_graph_version' => 'v2.2',
]);
if (!isset($_SESSION['fb_access_token'])){
try {
$helper = $fb->getRedirectLoginHelper();
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
//Exception of cross site forgery
}
if(!$accessToken){
$permissions = ['email','manage_pages','read_insights']; // Optional permissions
$loginUrl = $helper->getLoginUrl($options->redirect_uri."?update=facebook", $permissions);
wp_redirect($loginUrl);
exit;
} else{
if (!$accessToken->isLongLived()) {
$oAuth2Client = $fb->getOAuth2Client();
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
}
$_SESSION['fb_access_token'] = $accessToken->getValue();
wp_redirect($options->redirect_uri."?update=facebook");
exit;
}
} else{
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me/accounts', $_SESSION['fb_access_token']);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error.Click <a href="'.$options->redirect_uri.'?update=facebook">here</a> to try again.';
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error.Click <a href="'.$options->redirect_uri.'?update=facebook">here</a> to try again.';
exit;
}
$accounts = $response->getGraphEdge()->asArray();
//var_dump($response);
当我在响应中致电var_dump
时,我得到的是:
object(Facebook\FacebookResponse)#3611 (6) { ["httpStatusCode":protected]=> int(200) ["headers":protected]=> array(16) { ["vary"]=> string(15) "Accept-Encoding" ["etag"]=> string(42) ""1050253aec7b29caff644806927dabfa81406eee"" ["x-app-usage"]=> string(49) "{"call_count":0,"total_cputime":0,"total_time":0}" ["content-type"]=> string(31) "application/json; charset=UTF-8" ["facebook-api-version"]=> string(5) "v2.10" ["strict-transport-security"]=> string(25) "max-age=15552000; preload" ["pragma"]=> string(8) "no-cache" ["x-fb-rev"]=> string(10) "1000701931" ["access-control-allow-origin"]=> string(1) "*" ["cache-control"]=> string(44) "private, no-cache, no-store, must-revalidate" ["x-fb-trace-id"]=> string(11) "B7jB6SPnIpe" ["x-fb-request-id"]=> string(23) "..." ["expires"]=> string(29) "Sat, 01 Jan 2000 00:00:00 GMT" ["x-fb-debug"]=> string(88) "CSbxLbsnT7qUZ41r5fdDpKt7Xkqk2FF3Jil==" ["content-length"]=> string(2) "11" ["date"]=> string(29) "Sun, 12 May 2019 17:21:38 GMT" } ["body":protected]=> string(11) "{"data":[]}" ["decodedBody":protected]=> array(1) { ["data"]=> array(0) { } } ["request":protected]=> object(Facebook\FacebookRequest)#3613 (9) { ["app":protected]=> object(Facebook\FacebookApp)#3539 (2) { ["id":protected]=> string(15) "..." ["secret":protected]=> string(32) "607b756" } ["accessToken":protected]=> string(186) "..." ["method":protected]=> string(3) "GET" ["endpoint":protected]=> string(12) "/me/accounts" ["headers":protected]=> array(1) { ["Content-Type"]=> string(33) "application/x-www-form-urlencoded" } ["params":protected]=> array(0) { } ["files":protected]=> array(0) { } ["eTag":protected]=> NULL ["graphVersion":protected]=> string(4) "v2.2" } ["thrownException":protected]=> NULL }