Javascript 如何在墙上的帖子上获得用户的喜欢和评论?
我正在写一个程序,让所有的facebook帖子都出现在我的墙上。从这些帖子中,我想得到所有喜欢或评论某个帖子的用户的名字。我可以使用查询asJavascript 如何在墙上的帖子上获得用户的喜欢和评论?,javascript,facebook,facebook-graph-api,facebook-javascript-sdk,facebook-fql,Javascript,Facebook,Facebook Graph Api,Facebook Javascript Sdk,Facebook Fql,我正在写一个程序,让所有的facebook帖子都出现在我的墙上。从这些帖子中,我想得到所有喜欢或评论某个帖子的用户的名字。我可以使用查询as/me?fields=posts(尽管它只给我提供了25个喜欢我的帖子的人的名字)来获得这些信息。但是当我使用代码来做这件事时,它会给我一些东西,比如我喜欢的页面和我喜欢的相册,而不是我的墙贴。我已经添加了所需的所有权限 代码如下: <html> <head></head> <body> <div id=
/me?fields=posts
(尽管它只给我提供了25个喜欢我的帖子的人的名字)来获得这些信息。但是当我使用代码来做这件事时,它会给我一些东西,比如我喜欢的页面和我喜欢的相册,而不是我的墙贴。我已经添加了所需的所有权限
代码如下:
<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXXXXXX',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response){
if (response.status === 'connected') {
console.log(response.authResponse.accessToken);
testAPI();
} else {
FB.login();
}
},{scope:'email,user_likes,read_stream,user_status,status_update,share_item,video_upload,user_friends,create_node,photo_upload,publish_stream,publish_actions,export_stream,publish_checkins,share_item,video_upload'});
};
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api("/me?fields=posts", function(response) {
if (response && !response.error) {
console.log(response);
}
else {
console.log("Something's wrong");
}
});
}
</script>
<fb:login-button show-faces="true" size="xlarge" width="200" max-rows="1"></fb:login-button>
</body>
</html>
window.fbAsyninit=函数(){
FB.init({
appId:'xxxxxxxxxxxx',
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
FB.getLoginStatus(函数(响应){
如果(response.status===“已连接”){
log(response.authResponse.accessToken);
testAPI();
}否则{
FB.login();
}
},{范围:'email,user_like,read_stream,user_status,status_update,share_item,video_upload,user_friends,create_node,photo_upload,publish_stream,publish_actions,export_stream,publish_checkin,share_item,video_upload';
};
//异步加载SDK
(职能(d){
var js,id='facebook jssdk',ref=d.getElementsByTagName('script')[0];
if(d.getElementById(id)){return;}
js=d.createElement('script');js.id=id;js.async=true;
js.src=“//connect.facebook.net/en_US/all.js”;
ref.parentNode.insertBefore(js,ref);
}(文件);
函数testAPI(){
log('欢迎!获取您的信息…);
api(“/me?fields=posts”,函数(响应){
if(response&&!response.error){
控制台日志(响应);
}
否则{
console.log(“出了点问题”);
}
});
}
我还尝试使用FQL,使用查询
选择post\u id,likes,actor\u id,target\u id,message,comments FROM stream,其中source\u id=me()
。这给出了喜欢这篇文章的用户数量,但没有给出喜欢我的文章的用户的信息。请帮助。请查看以下链接:-
这可能会对您有所帮助。如果您只想更新状态,可以使用
GET /me/statuses
终点。如果您想对帖子进行更多筛选,请参阅流FQL表的类型字段:您可以在FQL的in列表中使用这些字段
您可以通过以下方式获得喜欢您的帖子的用户信息:
GET /me/statuses?fields=id,message,likes.fields(id,name,pic_square).limit(100),comments.fields(from.fields(id,name,pic_square)).limit(100)&limit=100
如果添加likes.fields(id、name、pic_square)
,其中字段列表可以是用户的任何字段。不幸的是,这与注释的工作方式不同,请参见上面查询的输出。您可以向包含数组的每个字段添加限制,以接收更多的结果
对于注释,我想您只能选择手动获取它们,并通过用户id(Graph API查询的id等于FQL查询的uid)将它们“连接”到Graph API的结果中
谢谢你的帮助。
GET /me/statuses?fields=id,message,likes.fields(id,name,pic_square).limit(100),comments.fields(from.fields(id,name,pic_square)).limit(100)&limit=100
select uid, name, pic_square from user where uid in (SELECT comments.comment_list.fromid FROM stream WHERE source_id = me() and type in (46, 80, 128, 247) limit 100)