我需要创建一个系统,当客户在他的网站上发布内容时,它将在他的Facebook上发布,但要做到这一点,我需要获取访问令牌,因为该帐户仍需要登录到我的系统。
我制作了自己的应用并在我自己的脸书中进行了测试,当我尝试通过我的系统登录时,它可以工作,但是当我尝试使用系统在客户端facebook登录时,返回此错误:
发生了错误。稍后再试。
我生成AccessToken的代码是:
require_once( “PHP-SDK / SRC / facebook.php”); //来自Git的最新SDK文件
$app_id = "APP_ID"; //ID do APP
$app_secret = "APP_SECRET"; //Secret do APP
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret
));
$page_id = 'PAGE_ID';
$message = "Teste de integração";
$token_url = 'https://graph.facebook.com/oauth/access_token?'
. 'client_id=' . $app_id
. '&client_secret=' . $app_secret
. '&grant_type=client_credentials';
$token_response = file_get_contents_curl($token_url);
$params = null;
parse_str($token_response, $params);
$app_access_token = $params['access_token'];
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
$page_info = $facebook->api("/$page_id/?fields=access_token");
//print_r($page_info);
if( !empty($page_info['access_token']) ) {
//if(!empty($app_access_token)) {
$args = array(
'access_token' => $page_info['access_token'],
'message' => $message
);
// print_r($args);
// $post_id = $facebook->api("/$page_id/feed","post",$args);
} else {
$permissions = $facebook->api("/me/permissions");
if( !array_key_exists('publish_stream', $permissions['data'][0]) ||
!array_key_exists('manage_pages', $permissions['data'][0])) {
// We don't have one of the permissions
// Alert the admin or ask for the permission!
header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")) );
}
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream, offline_access'));
}
?>
<?php if (!$user): ?>
<a href="<?php echo $loginUrl ?>">Login with Facebook</a>
<?php endif ?>
我已经尝试重新配置用户,并且用户的所有配置都与另一个没有返回错误的帐户相同。