Jan*_*ard 7 javascript facebook
我已经尝试使用FB.api将一些东西发布到我的Feed中几个小时了.我无法让它为我工作.我给了应用程序的权限.我可以使用PHP SDK发布到我的Feed,但我必须使用JavaScript.
<button onclick="doPost()">Post to Stream</button>
<script>
window.doPost = function() {
FB.api(
'/me/feed',
'post',
{ body: 'Trying the Graph' },
Log.info.bind('/me/feed POST callback')
);
};
</script>
Run Code Online (Sandbox Code Playgroud)
有人能给我一个简单的HTML页面的例子,它使用FB.api发布到一个feed吗?
Jan*_*ard 11
好吧,我让它自己工作了.当我从头开始使用新的HTML文件时,我不确定第一次出了什么问题.我希望它会帮助某人:
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
</head>
<body>
<a href="#" onClick="postToFacebook()">Post to Facebook</a>
<script>
function postToFacebook() {
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { body: body, message: 'My message is ...' }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response);
}
});
}
</script>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID GOES HERE',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(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>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29325 次 |
| 最近记录: |