我有这个代码在朋友的墙上发布消息,但是当我使用它时,我收到此错误:{“error”:{“message”:“无效的OAuth访问令牌。”,“类型”:“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>
答案 0 :(得分:0)
请参阅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
答案 1 :(得分:0)
自Facebook过去几个月以来,发布到朋友墙上的能力已经被移除或折旧,这与blog post中记载的相同。此外,如果您仍然希望允许用户发布到朋友的墙上,那么博客文章建议
如果您想允许其他人通过您的应用发布到朋友的时间轴,您可以调用feed dialog。通过user mentions tagging或action tagging包含朋友的故事将显示在朋友的时间轴上(假设朋友批准了该标记)。