Search for posts using Facebook Graph Api

不问归期 提交于 2019-12-09 00:17:59

问题


I want to search for posts(news-feed) using graph API for the past 30 days of data? what is the best practice to do that? And does Facebook Graph API has an API limit to limit the request of HTTP requests?


回答1:


NOTE: None of the below works anymore. As of version 2.3 of the Facebook Graph API, the search endpoint has been deprecated.

Copying from here under "Searching":

Searching

You can search over all public objects in the social graph with https://graph.facebook.com/search. The format is:

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 a q argument to the home connection URL:

* 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. 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. As per that, what you need to do is decode (using json_decode) the json object recevied by this url:

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.




回答2:


The best way is to use PHP's file_get_contents functions with that URL.

Failing that cURL will get the same response; just remember that any responses are in JSON format so use json_decode that you can start processing the information

A typical facebook feed should look like this;

$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. https://developers.facebook.com/docs/reference/api/




回答3:


It can be done with Graph API

As mentioned in the documentation, set since param to 30 days back. (Subtracting 30 days i.e 30*24*60*60 from current time stamp would provide the value or can also use strtotime)

And, yes there is limit on number of API calls, as mentioned in Facebook platform policies , the current limits are :

~(5M MAU) : 5 Million Authenticated Users for an app

~(100M API calls per day)

~(50M impressions per day).




回答4:


On August 17, 2016, FQL will no longer be available and cannot be queried...

i don't why Facebook change the whole SDK/API instead of updating it.




回答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.

<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

$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.


回答6:


You can use this call with an access token from the graph explorer, where the number is representative of a page ID:

123123123123123?fields=posts.limit(5)


来源:https://stackoverflow.com/questions/4880591/search-for-posts-using-facebook-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!