简体   繁体   English

使用Facebook Graph Api搜索帖子

[英]Search for posts using Facebook Graph Api

I want to search for posts(news-feed) using graph API for the past 30 days of data? 我想在过去30天的数据中使用图API搜索帖子(新闻Feed)? what is the best practice to do that? 这样做的最佳做法是什么? And does Facebook Graph API has an API limit to limit the request of HTTP requests? Facebook Graph API是否有API限制来限制HTTP请求的请求?

NOTE: None of the below works anymore. 注意:以下都不适用。 As of version 2.3 of the Facebook Graph API, the search endpoint has been deprecated. 截至Facebook Graph API的2.3版本,已弃用搜索端点。

Copying from here under "Searching" : 在“搜索”下从此处复制:

Searching 搜索

You can search over all public objects in the social graph with https://graph.facebook.com/search . 您可以使用https://graph.facebook.com/search搜索社交图中的所有公共对象。 The format is: 格式为:

https://graph.facebook.com/search?q=QUERY&type=OBJECT_TYPE https://graph.facebook.com/search?q=QUERY&type=OBJECT_TYPE

We support search for the following types of objects: 我们支持搜索以下类型的对象:

 * All public posts: https://graph.facebook.com/search?q=watermelon&type=post * People: https://graph.facebook.com/search?q=mark&type=user * Pages: https://graph.facebook.com/search?q=platform&type=page * Events: https://graph.facebook.com/search?q=conference&type=event * Groups: https://graph.facebook.com/search?q=programming&type=group * Places: https://graph.facebook.com/search?q=coffee&type=place&center=37.76,122.427&distance=1000 * Checkins: https://graph.facebook.com/search?type=checkin 

You can also search an individual user's News Feed, restricted to that user's friends, by adding aq argument to the home connection URL: 您还可以通过向主连接URL添加aq参数来搜索仅限该用户的朋友的单个用户的新闻Feed:

 * News Feed: https://graph.facebook.com/me/home?q=facebook 

That's one way of doing this. 这是实现这一目标的一种方式。 But your better bet will be using FQL , which is used by the JavaScript SDK , with the fb.dataquery method . 但是你最好的选择是使用JavaScript SDK使用的FQLfb.dataquery方法 What you want to do is use the stream table to get the status posts for users. 您要做的是使用流表获取用户的状态帖子。

Now, from your question, I understand that you rather use the PHP version over the Javascript Version. 现在,根据您的问题,我了解您更喜欢使用PHP版本而不是Javascript版本。 As per that, what you need to do is decode (using json_decode ) the json object recevied by this url: 根据这个,你需要做的是解码(使用json_decode )这个url json_decode的json对象:

https://graph.facebook.com/[USERNAME/USERID]?fields=posts&access_token=[A VALID ACCESS TOKEN]

As far as I know, this sould have no limit. 据我所知,这个没有限制。 However, take a look at the docs here . 但是,请看一下这里文档

The best way is to use PHP's file_get_contents functions with that URL. 最好的方法是使用PHP的file_get_contents函数和该URL。

Failing that cURL will get the same response; 失败的cURL会得到相同的回应; just remember that any responses are in JSON format so use json_decode that you can start processing the information 请记住,任何响应都是JSON格式,因此请使用json_decode开始处理信息

A typical facebook feed should look like this; 一个典型的Facebook提要应该是这样的;

$feedurl = "https://graph.facebook.com/$user_id/feed?access_token=$valid_access_token";
$feed = file_get_contents($feedurl);
$feed = json_decode($feed);
foreach ($feed->data as $post){
     //process each post
}

For searching as far as I can see there is no specific way to search a page or users news feed; 对于搜索,据我所知,没有特定的方法来搜索页面或用户新闻提要; but can search facebook via their search API. 但可以通过他们的搜索API搜索Facebook。 https://developers.facebook.com/docs/reference/api/ https://developers.facebook.com/docs/reference/api/

It can be done with Graph API 它可以使用Graph API完成

As mentioned in the documentation, set since param to 30 days back. 正如文件中所提到的, 因为 PARAM 30天返回设定的。 (Subtracting 30 days ie 30*24*60*60 from current time stamp would provide the value or can also use strtotime ) (从当前时间戳减去30天即30 * 24 * 60 * 60将提供价值或者也可以使用strtotime

And, yes there is limit on number of API calls, as mentioned in Facebook platform policies , the current limits are : 并且,是的,对于API调用的数量有限制,如Facebook平台政策中所述, 目前的限制是:

~(5M MAU) : 5 Million Authenticated Users for an app 〜(5M MAU):为应用程序提供500万经过身份验证的用户

~( 100M API calls per day ) 〜( 每天100M API调用

~(50M impressions per day). 〜(每天50万次印象)。

On August 17, 2016, FQL will no longer be available and cannot be queried... 2016年8月17日,FQL将不再可用,无法查询...

i don't why Facebook change the whole SDK/API instead of updating it. 我不知道为什么Facebook改变整个SDK / API而不是更新它。

您可以将此调用与图表资源管理器中的访问令牌一起使用,其中数字代表page ID

123123123123123?fields=posts.limit(5)

My dear just take an extended permission from the user either using login button or login url(in case of php sdk) then you just need to take access token, call make a json call to take the information whatever you like. 亲爱的,只需使用登录按钮或登录URL(在php sdk的情况下)获得用户的扩展许可,然后您只需要获取访问令牌,调用make json调用以获取您喜欢的任何信息。

<fb:login-button perms='read_stream' autologoutlink='true'></fb:login-button>

If you are having access token for user then you just call the graph api for this 如果您有用户访问令牌,那么您只需调用图api即可

$name=json_decode(file_get_contents('https://graph.facebook.com/USERID/feed?access_token='.Your ACCESS TOKEN));

It will return what you need. 它会返回你需要的东西。 But remember to replace 但请记住更换

USERID
with your user id and 用你的用户名和
 YOUR ACCESS TOKEN 你的访问权限 
with your access token. 使用您的访问令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM