我有一个应该从Facebook对象获取评论的页面,并使用JavaScript将它们发布到页面上,但是当用户登录时,我无法为我的生活弄清楚如何获取OAuth令牌。这是我的页面。如何从JavaScript API获取OAuth令牌?
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: 'myrealappid',
status: true,
cookie: true,
xfbml: true,
oauth: true,
});
};
(function (d) {
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
function getComments(objectid) {
//I need to append the OAuth token to this graph request
var commentUri = "https://graph.facebook.com/" + objectid + "/comments";
return $.getJSON(commentUri, function (json) {
var html = "<ul>";
$.each(json.data, function (i, fb) {
html += "<li>" + fb.message + "</li>";
});
html += "</ul>"
});
$('.comments').html(html);
};
$(document).ready(function() {
getTripComments(data.WallPostId);
});
</script>
<div id="pageLogo">
<img src="/images/page_logo.png" alt="Digital Mementos" />
</div>
<div id="container">
<div class="fb-login-button">Login with Facebook to Comment</div>
<div id="comments">
</div>
</div>
看看它说'我需要附加OAuth令牌到这个图请求'吗?是的,我需要这样做。我如何获得OAuth令牌?或者,我是否全力以赴?
谢谢!链接和代码很有用。我仍然在搞清楚“正确”的做事方式。 –
很高兴帮助... –