【问题标题】:Post to friends wall发布到朋友墙
【发布时间】:2013-05-06 23:04:03
【问题描述】:

我有这段代码可以在朋友的墙上发布一条消息,但是当我使用它时,我收到了这个错误:{"error":{"message":"Invalid OAuth access token.","type":"OAuthException ","代码":190}};

我能做些什么来解决这个问题?

有人可以帮助我吗?谢谢

这是我的代码:

require 'facebook-php-sdk-master/src/facebook.php';


$app_id = 'xxxxxxxxxxxxx';
$app_secret = 'xxxxxxxxxxxxxx';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));


$session = $facebook->getUser();


$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}

if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}


?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>Send Message</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $facebook->getAppId(); ?>',
session : <?php echo json_encode($session); ?>,
status : true, 
cookie : true, 
xfbml : true 
});


FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};

(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>

<?php if ($me){ ?>
<a href="<?php echo $logoutUrl; ?>">
<img src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">
</a>
<?php }else { ?>
<div>
<fb:login-button perms="publish_stream,offline_access"></fb:login-button>
<?php }
if ($me)
{
    $atoken=$facebook->getAccessToken();

$friends = $facebook->api('me/friends');
$message="This is a Test!";
for($i=0;$i<count($friends['data']);$i++)
{
$url="https://graph.facebook.com/".$friends['data'][$i]['id']."/feed";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS,"access_token=".$atoken."&message=".$message);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
}
}
?>

</body>
</html>

【问题讨论】:

  • 尝试检查向 facebook 发出的 HTTP 请求以获取令牌。您可以使用 chrome 检查器或 firebug 中的网络选项卡来执行此操作。确保请求正文中传递的数据是正确的。如果一切正确,则通过添加 die() 语句开始单步执行您的代码,这样您就可以打印出数据以查看沿途发生的情况,即die(var_dump($session));

标签: php facebook api token


【解决方案1】:

参见http://developers.facebook.com/docs/reference/api/errors/:您需要要求用户重新授权您的应用。页面说:

OAuth   190     C unless a subcode is present   Most OAuth errors include a subcode. Use the subcode table to determine the correct recovery tactic.

选项 C 说:

Authorize/reauthorize the user
Example: an expired token requires reauthorization of the application by the user

【讨论】:

    【解决方案2】:

    自过去几个月以来,Facebook 已取消或贬低在朋友的墙上发帖的功能,blog post 中也记录了这一点。另外,如果您仍然想允许用户发帖到朋友的墙上,博文建议

    如果您想允许人们从您的应用发布到他们朋友的时间线,您可以调用feed dialog。通过user mentions taggingaction tagging 包含朋友的故事将显示在朋友的时间线上(假设朋友批准标签)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-20
      • 1970-01-01
      相关资源
      最近更新 更多