Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Facebook社交图API搜索查找评论数量和评论列表?_Facebook_Facebook Graph Api - Fatal编程技术网

如何使用Facebook社交图API搜索查找评论数量和评论列表?

如何使用Facebook社交图API搜索查找评论数量和评论列表?,facebook,facebook-graph-api,Facebook,Facebook Graph Api,通过使用Graph Facebook API,我试图找到与特定关键字相关的所有公共内容 https://graph.facebook.com/search?q=obama&type=post 我得到了预期的结果,但最近我还想找到与特定结果相关的评论数量和个人评论列表 这是上述API调用的输出示例: { "id": "1372608125_2297171713409", "from": { "name": "xxxx", "id":

通过使用Graph Facebook API,我试图找到与特定关键字相关的所有公共内容

https://graph.facebook.com/search?q=obama&type=post  
我得到了预期的结果,但最近我还想找到与特定结果相关的评论数量和个人评论列表

这是上述API调用的输出示例:

{
     "id": "1372608125_2297171713409",
     "from": {
        "name": "xxxx",
        "id": "1372608125"
     },
     "message": "Originaly posted by:Anthony McMahan\n\n Political breakdown time....\n \nToday is short one, here is some information that will floor you if you werent aware of it yet. The United States of America makes approximately 15 trillion dollars annually GDP. Our debt has recently tipped over 15 trillion in recent days. So we now owe more than we make in a year. \n\nTo further add to the fury, medical facilities in the USA account for 1/6 of our GDP, so about 2.5 trillion dollars are brought in from hospitals across the US. the new healthcare bill is a stretch for the givernment to take control of all medical facilities in the US, which would basically cancel out 1/6 of our income as the healthcare would be made available to everyone. Therefore in light of the US being in more debt than we could make in a year, the plan is to take away 1/6 of our ability to make money. Imagine being in credit card debt and having to take a pay cut at work, because you chose to work in the mailroom instead of a cubicle. thats what is going on here in allegory. i would just like to take this time to say, \"thank you mr obama for making this country a laughing stock in the eyes of all our enemies and foreign nations, you'd make Karl Marx and Vladimir Lenin all too proud.\" \n\nUntil tomorrow........",
     "type": "status",
     "created_time": "2011-12-15T06:02:51+0000",
     "updated_time": "2011-12-15T06:02:51+0000"
  }  
http://graph.facebook.com/1372608125_2297171713409/comments  
假设我想找到与该帖子相关的评论数量和评论列表。我应该使用另一个API调用吗?
是否可以直接在“Graph API search”中知道注释的数量,而无需调用其他API?我需要这样做,如果一篇文章有评论,我将运行另一个API来获取评论列表,否则我不需要运行额外的API调用

据我所知,要获得单个注释的列表,我需要运行以下API调用:

{
     "id": "1372608125_2297171713409",
     "from": {
        "name": "xxxx",
        "id": "1372608125"
     },
     "message": "Originaly posted by:Anthony McMahan\n\n Political breakdown time....\n \nToday is short one, here is some information that will floor you if you werent aware of it yet. The United States of America makes approximately 15 trillion dollars annually GDP. Our debt has recently tipped over 15 trillion in recent days. So we now owe more than we make in a year. \n\nTo further add to the fury, medical facilities in the USA account for 1/6 of our GDP, so about 2.5 trillion dollars are brought in from hospitals across the US. the new healthcare bill is a stretch for the givernment to take control of all medical facilities in the US, which would basically cancel out 1/6 of our income as the healthcare would be made available to everyone. Therefore in light of the US being in more debt than we could make in a year, the plan is to take away 1/6 of our ability to make money. Imagine being in credit card debt and having to take a pay cut at work, because you chose to work in the mailroom instead of a cubicle. thats what is going on here in allegory. i would just like to take this time to say, \"thank you mr obama for making this country a laughing stock in the eyes of all our enemies and foreign nations, you'd make Karl Marx and Vladimir Lenin all too proud.\" \n\nUntil tomorrow........",
     "type": "status",
     "created_time": "2011-12-15T06:02:51+0000",
     "updated_time": "2011-12-15T06:02:51+0000"
  }  
http://graph.facebook.com/1372608125_2297171713409/comments  
这样做正确吗?在这里,我也不知道这篇文章是否真的有评论

实际上,我希望得到与Google+API类似的功能,在一个搜索API调用中,我可以得到如下回复(评论)数量:

"replies": {
 "totalItems": 53,
 "selfLink": "https://www.googleapis.com/plus/v1/activities/z13rhfhjzzm4ztrnt22kwpgglsrjdfra504/comments"
},

你最好的选择是让你的代码运行一个关于评论数量的计数,以获得线程中的评论数量(如果有的话)。不幸的是,要做到这一点,您必须调用/id/comments。我不知道有什么方法可以通过额外的API调用来实现这一点。

最好的办法是让代码运行注释数,以获得线程中的注释数(如果有)。不幸的是,要做到这一点,您必须调用/id/comments。我不知道有什么方法可以通过额外的API调用来实现这一点。

是的,您需要为每个帖子使用第二个API调用

是否可以直接在“Graph API search”中知道注释的数量,而无需调用其他API?我需要这样做,如果一篇文章有评论,我将运行另一个API来获取评论列表,否则我不需要运行额外的API调用

通常在阅读墙或提要时,您可以请求每篇帖子的
评论
字段,该字段将告诉您有多少评论(请尝试
/me/feed?fields=comments
)。无论出于何种原因,这在搜索API中似乎不可用,请求comments字段会从API返回一个错误

请求对帖子发表评论的正确方式确实是:

http://graph.facebook.com/1372608125_2297171713409/comments
如果你得到一个空的列表回来,没有评论。否则,您将得到一个评论列表。如何检查这一点取决于您使用的语言。对于没有注释的帖子,返回的原始JSON数据如下所示:

{
  "data": []
}
非常活跃页面上的帖子可能有数千条评论,因此如果您计划点击其中的许多评论,您可能需要指定
limit
参数,一次获取一堆评论:

http://graph.facebook.com/1372608125_2297171713409/comments?limit=1000

如果评论少于1000条,您将立即获得所有评论。

是的,您需要为每篇文章使用第二个API调用

是否可以直接在“Graph API search”中知道注释的数量,而无需调用其他API?我需要这样做,如果一篇文章有评论,我将运行另一个API来获取评论列表,否则我不需要运行额外的API调用

通常在阅读墙或提要时,您可以请求每篇帖子的
评论
字段,该字段将告诉您有多少评论(请尝试
/me/feed?fields=comments
)。无论出于何种原因,这在搜索API中似乎不可用,请求comments字段会从API返回一个错误

请求对帖子发表评论的正确方式确实是:

http://graph.facebook.com/1372608125_2297171713409/comments
如果你得到一个空的列表回来,没有评论。否则,您将得到一个评论列表。如何检查这一点取决于您使用的语言。对于没有注释的帖子,返回的原始JSON数据如下所示:

{
  "data": []
}
非常活跃页面上的帖子可能有数千条评论,因此如果您计划点击其中的许多评论,您可能需要指定
limit
参数,一次获取一堆评论:

http://graph.facebook.com/1372608125_2297171713409/comments?limit=1000

如果评论少于1000条,您将立即获得所有评论。

更简单的方法是使用所谓的“批处理请求”。它允许您一次执行多个Graph API请求,甚至允许您定义请求之间的依赖关系。可以找到完整的文档(您需要向下滚动到“指定请求中操作之间的依赖关系”)

您的第一个请求将是搜索结果,第二个请求将取决于第一次调用的结果,使用每个结果的图形ID来获取每个搜索结果的注释


我还没有处理依赖的批处理请求,但您应该尝试一下:-)

更简单的方法是使用所谓的“批处理请求”。它允许您一次执行多个Graph API请求,甚至允许您定义请求之间的依赖关系。可以找到完整的文档(您需要向下滚动到“指定请求中操作之间的依赖关系”)

您的第一个请求将是搜索结果,第二个请求将取决于第一次调用的结果,使用每个结果的图形ID来获取每个搜索结果的注释


我还没有处理依赖的批处理请求,但您应该试一试:-)

哪个API调用将返回注释数?我尝试使用/id/comments调用,但结果为空。这是否意味着该帖子没有评论?是的。如果/id/comments返回空结果,则post为空。您应该能够使用正在编码的语言的函数来检查此调用返回的结果数量。如果它说有0,那么就没有任何评论。谢谢。我还是很好