Get "Post Count" from public page using Facebook Graph API - facebook

I want to get a number of posts from a page in last month. Is is possible with facebook graph API? Also FYI, i just have the access_token to interact with the Facebook API.
Also do anyone knows how to fetch the number of Page mentions in last month?
Thanks for your help in advance.

Try using Facebook's Page Insights using Facebook Graph API's :
https://developers.facebook.com/docs/graph-api/reference/insights/#page_posts
But please note that you need to be a page admin for this page, and you need to acquire a Page Access Token with the permissions 'read_insights'.
If you are not a page admin, then you can also do the same with an User Access Token or an App Access Token.
Steps:
`int postsCount = 0;
Use the following API query https://graph.facebook.com/{page-id}/posts and issue a reuquest.
Count the posts fetched. postsCount = postsCount + {the posts json array size}.
Store the cursor returned by the above API result. Use it to fetch the next page of Posts.
If the {the posts json array size} > 0, then goto step 3.
Notes:
I am sure that you can do it better with FQL, but I am guessing FQL is being deprecated.
I think there is a summary(true) annotation (https://graph.facebook.com/{page-id}?fields=posts.summary(true)) that you can use, but I couldn't get it working.
There is an API rate limit that you need to keep in mind. And do some throttling.
So, the moral of the story is that I am not sure if Facebook really wants you to crawl its Pages if you are not the Admin of the page. :-)

Related

Some public wall posts missing in facebook api response

I use the facebook api to crawl post from one page wall. The post will be published by random facebook users. The posts are shown on a landingpage.
That work's very fine for the first dev tests. But since we have switch into a live version (now random user write posts) where are some posts that are not in the facebook api's response.
My first thought was that the privacy setting of the post is not public. But then I shouldn't see it when I am logout.
Why I didn't see that few posts? Have someone a tip?
$url = '/' . $pageId . '/feed?fields=from, message, id, link, type, created_time, updated_time, shares, object_id,comments.limit(1).summary(true),likes.limit(1).summary(true)&since=' . $since;
Try adding &filter=stream to your call.
Facebook will defaults to a "Top Story" feed which can hide some objects due to a low "score". This will force the return to be in a "Most Recent" style feed where all objects will be shown and in chronological order.
My Idea: Some posts are missing in the api because of the privacy setting of facebook user? Maybe because the profile is not visible for non-facebook users? The publicity of the posts on facebook wall is always public when i look at the facebook wall. Have somebody experience with that?

Facebook PHP SDK Issue with specific Facebook Id

Im using the following to retrieve information about Facebook pages that I'm the admin of. Specifically the number of likes.
// Get User ID
$page = $facebook->api($id);
return $page['likes'];
This works fine for 20 Facebook pages that I admin but I've run into one case where it does not. This is the error that I'm getting in response.
Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
I have checked that the Id being used is correct by viewing the Facebook Id Page under the admin settings. http://findmyfacebookid.com/ also runs into an error when entering the pages url.
Has anyone else experienced this? Is this a bug?
I am pretty sure you are not using an Access Token to grab the Page likes, and that one Page is restricted by age or country. Either that, or it is unpublished. Also, calling the return value "$user" may be misleading, it is not a User object, it is a Page object, right?
For restricted Pages you MUST use a User or Page Access Token of a User who can access the Page.

How can I make my timeline with Graph API?

I've studied Facebook API for several hours, and googled lots of pages. But I can not find the way get posts list just like my timeline on Facebook app.
I would like to make a Web app that show my timeline posts just like Flipboard. I found an API to get my "story" and "my friends list". But I can not even imagine how to retrieve my friend post that shown on my timeline.
Is it impossible to replicate my timeline on my web app? Only Flipboard can do that? Do you have any hint?
To access the current User's News Feed use the "User/Home" request as described in the API Documentation.
In order to gain access to the User's News Feed you will be required to gain the "read_stream" permission. For information on how to request the appropriate permission, read the Login, authorization and permissions section of the Getting Started guide.
The request to me/home will return an array of News Feed items, which are comprised of statuses, pictures, likes, etc. You can see an example of the result by using the Graph API Explorer.
Compare the results to your Timeline and they should be nearly identical (currently I believe Ads/Promoted Posts are excluded from the API)"
Play around with the Graph API Explorer:
https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fhome
I had to change the permissions within the App and specifically give myself 'read_stream' access, but once that was complete I was able to run a '/me/home' Graph API GET Request and return a representation of my timeline. Good luck!
You can get the timeline this way:
$fb = new Facebook('{config}');
$fb->setDefaultAccessToken('{getAccesstoken}');
$request = $fb->get('/me?fields=feed.limit(10000){link}');
//
$graphObject = $request->getGraphNode();
return $graphObject;

Get Facebook Page Feed and their likes/comments without any permissions

I am trying to get the user ids of all the users who have liked or commented on a status on a facebook page.
I tried using graph.facebook.com/page_id/posts?access_token=...
but it only gives me 2-4 user ids who have liked and their total count, similarly for comments. Is there any way to get all the ids?
According to The Documentation for the 'Post' object
(and verified by me on my own page using the Graph API Explorer tool), these work:
/POST_ID/comments to fetch the comments
/POST_ID/likesto fetch the Likes

Any way to pull likes by dates from facebook graph api? (New Likes instaed of Global Likes)

I basically need an access to a fanpage's likes by dates, i mean.. not the global likes when you access the graph but the ability to see how much likes the page got yesterday/today..
Any way to do that?
Have a look at https://developers.facebook.com/docs/reference/fql/insights/#page_users - you (by which I mean the user of your app) need to be admin of the page though. You get page_fans, *_adds, *_removes, etc.. On how to execute FQL using the Graph API: https://developers.facebook.com/docs/reference/fql/