我有这段代码在朋友的墙上发布消息,但是当我使用它时,我收到这个错误:{“error”:{“message”:“无效的 OAuth 访问令牌。”,“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>