Periodically fetch Facebook like,share and comment count for all pages within domain - facebook

We are to create a statistics module for our news portal which involves crawling like and share count for each article (~7000 urls and continuously increasing).
The statistics is to be regenerated at least daily and without user iteraction.
We tried using fql without access_token (as it would involve user iteraction):
select ... from link_stat where url = ...
select ... from link_stat where url IN (...,...,...)
same with multiquery
But we are getting 403 Forbidden response after a few requests and the actual ip "banned" (all other requests without access_token result in 403) for some time.
Is there a proper way of collecting like and share counts for the particullar website?

A quick way to query facebook using FQL is to install the "fbcmd" app. This app lets you access the facebook and execute FQL statements from command line. It needs authorization once, during installation. After that, you can execute any number of queries.

Related

Facebook graph api - Unsupported get request

I'm creating a custom module in Drupal, that for part of its functionality must fetch posts from a business page. So for simplicity, I'm using fbapp module as a dependency (drupal.org/project/fbapp), so that I can use it's authentication and request functions (fbapp_app_authenticate() and fbapp_graph_request()) without having to worry about the constant facebook graph updates making my own code obsolete.
I've created a facebook app, so authentication should be app token, using appid and app secret. This seems fine and I'm getting back access_token. However, when I try to read posts from a publicly available page (the clients), I get the response:
"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api"
Here's the queries and responses my code produces:
graph.facebook.com/oauth/access_token?client_id=<redacted>&client_secret=<redacted>&grant_type=client_credentials
array(1) {
["access_token"]=>
string(43) "<redacted>|<redacted>"
}
graph.facebook.com/<page_id>/posts?access_token=<redacted>|<redacted>"
string(183) "{"error":{"message":"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100}}"
Can anyone verify a correct way to query a Facebook page programmatically, perhaps there's a setting in the page I'm querying that I need to set (although I can't find anything)?
If page restrictions apply, the page's feed can only be retrieved with an user access token as far as I know (because FB needs to evaluate the visibility criteria, and setting your app to the same restrictions doesn't help here):
See
https://developers.facebook.com/docs/graph-api/reference/v2.4/page/feed#readperms
It looks like everything you have done is correct. The response you got can be (i am not sure) because you got your clients pageid wrong.

How to get Facebook page total likes number with the new Graph API (v2.4)

So recently there was a update to the Facebook Graph API and now pretty much everything requires a access_token to retrieve any type of data.
Previously you could get the number of page likes by accessing the graph like so:
http://graph.facebook.com/{page-name}
But now if you try it says you need to have a access token because of a recent update to the API. Now the issue i am having is i cant access the likes even with an access token this is the response i am getting:
Request
http://graph.facebook.com/{page-name}/?access_token={access_token}
Response
array(2) {
["name"] "Page Name"
["id"] "Page Id"
}
Now at first i thought the access token wasn't being generated with the correct scopes but i am 99% sure you only need read_stream to pull that type of data.
Second thought is that they have removed the ability to acces likes of any page and you need a page token to receive that type of data or finally i am missing something incredibly small here and its still achievable?
So my question is can you still get the number of likes of any page using the Facebook Graph API and if the answer is yes how do you do it?
any help appreciated
This can help you! Just add ?fields=likes after the page name/id. You can use any access token for fetching data!
graph.facebook.com/{page_name}?fields=likes&access_token={token}
The Graph API v2.4 reduces the number of fields in default responses.
https://developers.facebook.com/blog/post/2015/07/08/graph-api-v2.4/
Fewer default fields for faster performance: To help improve performance on mobile network connections, we've reduced the number of fields that the API returns by default. You should now use the ?fields=field1,field2 syntax to declare all the fields you want the API to return.
If you do ?fields=likes it should show up.
You can do like this:
https://graph.facebook.com/v2.4/{page_id}/fields=likes

Facebook FQL posts limit issue

Currently i am using following FQL query :-
https://api.facebook.com/method/fql.query?query=select post_id,likes FROM stream WHERE source_id=XXXXXXXX LIMIT 0,10000&access_token=XXXXXXXXXXXXX&format=json
I have two Facebook Accounts / pages & able to download data using above API. Able to retrieve posts & post likes count.
But, from last three days, for one Facebook account above FQL query is not working. it is returning message :- "error": "Request failed" . For other account it is working fine.
For each facebook Account / pages i have generated separate Access Tokens.
But, if i update limit from : -
Limit 0,50
Limit 50,100
then it is working & returning posts from page but not returning all post which i have previously getting from Limit 0,10000
Please help me, if any one have idea about this issue ?
Thanks
Facebook will cancel queries which take too long or too many resources to execute. In general, I would never use LIMITs which are that high. There's a high probability that they will fail, and you can't really incfuence the query execution "load" other than setting the LIMIT to a reasonable number (which means implementing a paging mechanism).

Having trouble with Facebook FQL - Empty Return

I'm attempting to make a Facebook app that will query insights metrics from pages that I administer. I'm unsure if there is a better approach, but I am running into issue after issue trying to build my queries.
For instance, many of the "metric" fields listed here return empty data objects. Testing the following FQL query on the Graph API Explorer is an example (substitute with your page ID):
fql?q=SELECT metric, value FROM insights WHERE object_id=<USER_ID> AND metric='post_storytellers' AND period=0
I have granted myself "read_insights" permissions.
I'm wondering if this is a common issue, if I'm doing this wrong, and if there is a better way (i.e. FQL is problematic, stick to the Graph API). I started this project using Perl, intending to simply parse the return data into a database. Perhaps I would be better served writing this in PHP?
The post_storytellers metric, has only 3 available periods: day, week and days_28. When you put period=0, you are asking for the lifetime period.
Your query should be something like this:
SELECT metric, value FROM insights WHERE object_id=<PAGE_ID> AND metric='page_storytellers' AND end_time=1334905200 AND period=period('week')
I hope it would help!

How to delete a Facebook comment post using the Facebook GRAPH API?

I started researching this because I wanted to be able to delete a comment on the wall of a Facebook Event, because the "Remove post" doesn't seem to be applicable to comments on an Event wall. However, since I don't know if it is even possible I decided to see if I could mannually delete a post I made to my own wall first since that is possible. Note I am NOT using any SDK; I am just building the URL and entering it in the address bar in Firefox v3.6.17.
These posts have helped me alot since I am now starting:
Delete facebook post with Graph API - trouble getting this to work and
Facebook SDK and Graph API Comment Deleting Error
I can see the comment data and all its field via the following:
https://graph.facebook.com/[POST_ID]?access_token=[ACCESS_TOKEN]
`where [POST_ID] and [ACCESS_TOKEN] were got using the graph API.`
However, where do I put the "method=delete" command in the URL? I tried putting it at the end, like
https://graph.facebook.com/[POST_ID]?access_token=[ACCESS_TOKEN]?method=delete
but that results in a OAuthException stating "Invalid access token signature" because it seems to read the method as part of the access token.
I tried putting it after the post_id like
https://graph.facebook.com/[POST_ID}?method=delete?access_token=[ACCESS_TOKEN]
but that results in an Exception (Unsupported method) because it thinks "access_token=[ACCESS_TOKEN]" is part of the method being called.
I see one of the posts cited above states I have to prepend the userid to the object ID when deleting by using
DELETE https://graph.facebook.com/673509687_104812882909249?access_token={access_token}
`where 673509687 is my userID and 104812882909249 is the objectID`
But when I enter
DELETE https://graph.facebook.com/[POST_ID}?access_token=[ACCESS_TOKEN]
in the Firefox address bar it doesn't recognize it (I didn't think it would anyway) and uses it as a google search query.
How do I delete a comment if I have the comment_id and my access_token using the web browser?
You have a big problem with your urls :
https://graph.facebook.com/[POST_ID]?access_token=[ACCESS_TOKEN]?method=delete
Should be :
https://graph.facebook.com/[POST_ID]?access_token=[ACCESS_TOKEN] & method=delete
Identically,
https://graph.facebook.com/[POST_ID}?method=delete?access_token=[ACCESS_TOKEN]
should be :
https://graph.facebook.com/[POST_ID}?method=delete & access_token=[ACCESS_TOKEN]
So you have to use the ? before entering your parameters and then & between each parameter and the order should not have any importance ..