关于facebook图形api的一个小问题。我一直在使用官方的Facebook Graph。
我还在我的网页上加入了facebook社交评论插件。是否可以在网页上发布评论,使用facebook的Graph?
用户将使用facebook登录到我的web应用程序中,然后他必须能够通过API在我的应用程序中的网页上发布facebook评论。因此,小部件将显示直接发布在页面上的所有注释,以及通过API发布的注释。
到目前为止,我已经尝试过以下AJAX代码:
<?php
$token = $facebook->getAccessToken();
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"
type="text/javascript"></script>
<script type="text/javascript">
$.post('https://graph.facebook.com/comments/?ids=http://mywebsite.com/comments.php?id=123',{ name: 'John', message: 'Testing comments', 'method': 'POST', 'format': 'json', 'access_token': '<?php echo $token; ?>'},
function(data) {
});
</script>
但这将返回一个OAUTH异常:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1
}
}
在设置登录url时,我正在请求足够的权限:
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'email,publish_stream,publish_actions,read_stream,user_about_me,user_events,create_event'
));
备注:我正在使用以下代码将facebook小部件包括在我的页面上:
<div class="fb-comments" data-href="http://www.mywebsite.com/comments.php?
id=<?php echo $_GET['id']; ?>" data-width="370" data-num-posts="5"></div>
脚本:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=xxxxxxxxxxxxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<!--<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>-->
<p id='msg'></p>
<script>
FB.init({appId: "xxxxxxxxxxxxxxx", status: true, cookie: true});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
redirect_uri: 'http://www.mywebsite.com/comments.php?id=<?php echo $_GET['id']; ?>',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: 'Facebook Dialogs',
caption: 'Reference Documentation',
description: 'Using Dialogs to interact with users.'
};
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
</script>
发布于 2013-02-01 11:45:05
这不是发布评论的正确语法。至少缺少了postId :这里您如何通过API (php )调用它
$facebook ->api('/'.$post_id.'/comments',
'post',
array(
'message' => 'users comment',
)
);
不能使用JQuery $.post生成APi调用。使用JQuery调用包含API调用的PHP脚本。
https://stackoverflow.com/questions/14643760
复制相似问题