我已经用谷歌搜索了 2 天,但找不到任何确定的信息。我遇到的所有结果都使用不再有效的弃用代码。请帮忙。
我需要一个点击按钮...
- 检查扩展权限
- 如果尚未授予权限,请请求它们(user_likes、offline_access、publish_stream)
- 获得权限后,将帖子发布到用户的墙
- 允许我在用户离线时向他们推送墙帖
有人可以帮忙吗?
最佳答案
这很简单。您可以调用 FB.login 来获得扩展权限。然后你可以调用 FB.ui 来发布状态(或者 FB.api 来调用/me/feed 来发布而无需用户交互,这是不受欢迎的)。为了能够在以后推送墙帖,您需要将 access_token 存储在您的服务器上以供以后使用。
<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
<a href="#" onclick="return postToWall();">Post To Wall</a>
<script src="//connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId: '**appID**', status: true, cookie: true, xfbml: true, oauth: true });
function postToWall() {
FB.login(function(response) {
if (response.authResponse) {
FB.ui({
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
});
} else {
alert('User cancelled login or did not fully authorize.');
}
}, {scope: 'user_likes,offline_access,publish_stream'});
return false;
}
</script>
</body>
</html>
关于facebook-graph-api - Facebook JS SDK——权限检查后发布到墙上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7397325/