Facebook API How To Get All Pages I Like Without Pagination - facebook

If I like more than 100 pages/things, FB.API('me/likes') returns 99 items and a link to the next paging.
Is it possible to get ALL without the pagination?
Thanks

Have you tried /me/likes?limit=999 ?
You may still need to paginate, but you should be able to get more than 99 items in a single call

Use FQL:
$fql = "SELECT page_id from page_fan where uid = me())";
$pages_i_liked = $facebook->api(array(
'method'=> 'fql.query',
'access_token' => $access_token,
'query'=> $fql,
));
print_r($pages_i_liked);

Get All facebook pages of a user using facebook api
required permissions: manage pages
type: GET
url: https://graph.facebook.com/me/accounts
param: access_token
responce of the above request like this
{
"data": [
{
"category": "Book",
"name": "Mind blowing books",
"access_token": "CAACEdEose0cBAFRU2j0rGgNxBcJvU0pkZCpDbI7rZCJNmO2cZAfZBXoejoZCdTVdKi4gNCyBuu9fPRnWRAwCKrmkPePzKHoE5e46Jz7gRDYe3PM5ECm0ZC5OZB2iWLeEh3OZBgTGfWDmQbbFivwlp5v2umc0CcC9JlTvHsWDnTZCkKIbZAJeD2nOus1ZCCXMqSXHOAZD",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
],
"id": "618353601555775"
}
],
"paging": {
"next": "https://graph.facebook.com/100000328561058/accounts?access_token=CAACEdEose0cBADKMTNRBl5pjNhw8xsKnQf57XKShV7UlhGyJy67bBZCUKkepl9rELlxqq0I474f8LEPGnt51Mdgs0MMtgTycuUgkOyRnLgVypWVpBd7oKy3LXrrbsQWSdIUZBU4qKHLxSb14TP8ySOaZChLseseYMr1YMLG3qrJiWLuwWJeVz2PeE8TmkkZD&limit=5000&offset=5000&__after_id=618353601555775"
}
}
Post at specific facebook page of a user using facebook api
required permissions: piblish action
type: Post
url: https://graph.facebook.com/{PAGE_ID}/feed
param: access_token, message
this http request will write your message on fb page
PAGE_ID: its page id which is in responce of first request

The maximum results limit is 100
"I just noticed this while counting the results and also next page query, if I insert limit 999 for example, the exact results will be shown as 100 and the next link generated by facebook will contain the limit value also 100"

With this class from Github: FacebookLikedPagesAPI you can get all ID liked pages on Facebook without pagination
$access_token = '';// your access token here
$likes=new Likes();
$result=$likes->getAllLikedPages($access_token);

Related

can't exchange token manually v2.7

I'm using Loopback and
I'm trying to user auth for graph api without javascript sdk or passport
I got the code successfully however I can't exchange it with access token
I followed this guide https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/#confirm
my get request is https://graph.facebook.com/v2.7/dialog/oauth?code={xxxx}&client_secret={xxxx}&client_id={xxx}&redirect_uri={myURL}
myURL is the one used to get the code but not be used again if I understand
If I understand correctly I should it the access_token in the body of the response instead I get this error
{
"error": {
"message": "Unknown path components: /oauth",
"type": "OAuthException",
"code": 2500,
"fbtrace_id": "HXe+214tGpW"
}
}
It looks like a bug in the docs. The first call is to www.facebook.com in a browser.
See here for an example client https://github.com/yschimke/oksocial/blob/master/src/main/java/com/baulsupp/oksocial/services/facebook/FacebookAuthFlow.java
The second should be to something like https://graph.facebook.com/v2.7/oauth/access_token
$response = $fb->sendRequest(
'GET',
'/oauth/access_token',
[
'client_id' => $config['client_id'],
'client_secret' => $config['client_secret'],
'grant_type' => 'fb_exchange_token',
'fb_exchange_token' => $short_token
],
$short_token,
null,
'v2.7');

Get page access token with Facebook API 5.0 PHP

I need to post messages on a Facebook page. Specifically I want to post via cron.
Here's what the API docs say:
Page Access Token – These access tokens are similar to user access tokens, except that they provide permission to APIs that read, write or modify the data belonging to a Facebook Page. To obtain a page access token you need to start by obtaining a user access token and asking for the manage_pages permission. Once you have the user access token you then get the page access token via the Graph API.
How I can obtain a user access and page access token without a page callback? Is this possible?
What you need it an Extended Page Token, it is valid forever. You get one like this:
Authorize with the manage_pages permission (and publish_pages if you want to post as Page later), to get a User Token
Extend the User Token
Use /me/accounts?fields=access_token with the Extended User Token to get a list of all your Pages with Extended Page Tokens - or use /page-id?fields=access_token to get an Extended Page Token for a specific Page
Information about all Tokens and how to extend the User Token:
https://developers.facebook.com/docs/facebook-login/access-tokens#extending
http://www.devils-heaven.com/facebook-access-tokens/
PHP API V5
The below code worked for me after 24 hours of head scratching .... hope this helps by the way if you need this code to work you should have completed the first two steps
Should have login to facebook I used getRedirectLoginHelper
Set session variable with the received user access token on the call back file $_SESSION['fb_access_token'] = (string) $accessToken;
$fbApp = new Facebook\FacebookApp( 'xxx', 'xxx', 'v2.7' );
$fb = new Facebook\Facebook( array(
'app_id' => 'xxx',
'app_secret' => 'xxx',
'default_graph_version' => 'v2.7'
) );
$requestxx = new FacebookRequest(
$fbApp,
$_SESSION['fb_access_token'],//my user access token
'GET',
'/{page-id}?fields=access_token',
array( 'ADMINISTER' )
);
$responset = $fb->getClient()->sendRequest( $requestxx );
$json = json_decode( $responset->getBody() );
$page_access = $json->access_token;
//posting to page
$requesty = new FacebookRequest(
$fbApp,
$page_access ,
'POST',
'/{page-id}/feed?message=Hello fans YYYYYYYYYYYYYYY'
);
$response = $fb->getClient()->sendRequest( $requesty );
var_dump( $response );
You can get the page token this way:
$response = $fb->get('/'.$pageId.'?fields=access_token', (string)$accessToken);
$json = json_decode($response->getBody());
$page_token = $json->access_token;
$response = $fb->post('/'.$pageId.'/feed', $fbData, $page_token);
I've only JavaScript code, but once you have an access token, you may get the pages which can be adminstered by the given user. This will contain a page access token for each of them:
jQuery.ajax({type: "GET",
url: "https://graph.facebook.com/v2.2/me/accounts?access_token=" + userToken,
async: false,
data: jsonRequest,
dataType: "json",
cache: false,
success: function(data)
{
The data given back is like:
{
"data": [
{
"access_token": "CAACni8TcBB0B...cZBJfwZDZD",
"category": "Computers/Technology",
"name": "abc",
"id": "...",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
},
{
"access_token": "CAA...ZDZD",
"category": "App Page",
"name": "xyz",
"id": "....",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
}
],
access_token is your page token. You may transform the above request into PHP easily.

FQL NoIndexFunctionException error 605 on an indexable column

I'm attempting:
SELECT developer_id FROM app_role WHERE application_id='MY APP ID'
Using a valid token, checked using https://developers.facebook.com/tools/explorer
I receive this back:
{
"error": {
"message": "Invalid application_id in WHERE clause",
"type": "NoIndexFunctionException",
"code": 604
}
}
Now. the application_id is definitely correct. The auth token is checked and associated with that app id, and as far as I can see application_id is totally indexable.
Any ideas what the grief is here? Thanks.
That's because you need an app access token. Get it this way:
GET https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID
&client_secret=YOUR_APP_SECRET
&grant_type=client_credentials
Source: https://developers.facebook.com/docs/opengraph/howtos/publishing-with-app-token/
Then, use the same FQL request:
SELECT developer_id FROM app_role WHERE application_id='MY APP ID'
And there you go:
{
"data": [
{
"developer_id": "1234567890"
},
{
"developer_id": "9876543210"
}
]
}

how to get user id on facebook request dialog

What i want to do is get the request ID and insert to my database. My request dialog is run well, but the problem is I cannot get 'TO' user id http://developers.facebook.com/docs/reference/dialogs/requests/ , but I still cannot get the request user ID.
here is my coding:
function newInvite(){
//var user_ids = document.getElementsByName("user_ids")[0].value;
FB.ui({
method : 'apprequests',
title: 'X-MATCH',
message: 'Come join US now, having fun here',
},
function getMultipleRequests(requestIds) {
FB.api('', {"ids": requestIds }, function(response) {
console.log(response);
});
}
);
}
any solution on this?
million thanks for help
Have you enable request 2.0 efficient?
If you have enabled, you can get the user id easily as the response like this
{
request: ‘request_id’
to:[array of user_ids]
}
In your callback function, you can use
response.request to get the request ID
response.to to get the array of user ids
And notice that if you use request 2.0, the request ID format will like this
<request_object_id>_<user_id>
If you doesn't enable it, then you can only get the array of request ids and you need to make another api call to get the user id
Edited:
FB.ui({
method : "apprequests",
title : "your title",
message : "your msg"
},
function(response) {
var receiverIDs;
if (response.request) {
var receiverIDs = response.to; // receiverIDs is an array holding all user ids
}
}
);
Then you can use the array "receiverIDs" for further process
For example I sent a request to user id with id "1234", "5678"
The response will like this:
{
request: ‘1234567890’ // example,
to:['1234', '5678']
}
In request 2.0, the full request id will look like this
1234567890_1234
1234567890_5678
Caution: FB doc tell you to manage and delete the request yourself, if you using request 2.0,
remember to delete the id like the above, if you directly delete the request '123456789', all the full request ID with this prefix will be deleted.
==================================================================
If you haven't enable request 2.0, follow the code on the doc page to see how to get the user id by making a api call
function getMultipleRequests(requestIds) {
FB.api('', {"ids": requestIds }, function(response) {
console.log(response);
});
}
The response format for these methods is as follows:
{
"id": "[request_id]",
"application": {
"name": "[Application Name]",
"id": "[Application ID]"
},
"to": {
"name": "[Recipient User Name]",
"id": "[Recipient User ID]"
},
"from": {
"name": "[Sender User ID]",
"id": "[Sender User Name]"
},
"message": "[Request Message]",
"created_time": "2011-09-12T23:08:47+0000"
}
you can implement the callback of api call and getting who is the receiver by response.to.id

Facebook API: How to get count of group members

Im working on fb app using PHP client and FQL.Looks like that fb api doesnt support this. You can get max random 500 members with FQL. But when group has more than 500 members there is no way how to get total count of members.
I need only number dont care about member details.
Anyone can help me please?
I have actually found that you cannot, it is by design apparently. I wanted to know this myself about a month ago, and found that no matter what parameters you pass in to the graph api, you can not get past the 500th member. Even if you tell it to start at number 450 and give you 200, it will give you only 450-500.
Here's me asking, and the unfortunate answer:
http://forum.developers.facebook.net/viewtopic.php?id=82134
you can use graph api 2.0 and sdk 4.0
you can use below code
$url1= "https://graph.facebook.com/".$gid."/members?limit=10000&access_token=".$_SESSION['fb_token'];
if(!extension_loaded('curl') && !#dl('curl_php5.so'))
{
return "";
}
$parsedUrl = parse_url($url1);
$ch = curl_init();
$options = array(
CURLOPT_URL => $url1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => array("Host: " . $parsedUrl['host']),
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => false
);
curl_setopt_array($ch, $options);
$response_count = #curl_exec($ch);
$json_count = json_decode($response_count);
foreach ($json_count as $item_count)
{
$cnt=count($item_count);
break;
}
You can use the summary parameter which will return a total_count value.
/v2.11/{GROUP_ID}?fields=members.limit(0).summary(true)
It also works when searching for groups:
/v2.11/search?q=stackoverflow&type=group&fields=id,name,members.limit(0).summary(true)
{
"data": [
{
"id": "667082816766625",
"name": "Web Development Insiders",
"members": {
"data": [
],
"summary": {
"total_count": 2087
}
}
},
{
"id": "319262381492750",
"name": "WEB Developers India",
"members": {
"data": [
],
"summary": {
"total_count": 10240
}
}
}...
]
}
Make a query to:
https://graph.facebook.com/v2.11/{group-id}/members?limit=1500&access_token={token}
(replace {group-id} by the numeric group identification and {token} by your access token).
You will get a response like this:
{
"data": [
{
"name": "Foo bar",
"id": "123456",
"administrator": false
},
...
],
"paging": {
"cursors": {
"before": "QVFIUkwzT3FKY0JSS2hENU1NUlZAocm9GelJMcUE3S1cxWWZAPYWx1cUQxcXFHQUNGLUJnWnZAHa0tIdmpMT0U5ZAjRBLUY5Q2ZAGbmwwVTNoSHhLc1BCc2dvVTF3",
"after": "QVFIUkFoU3lYR2tXc09adkg5OGhlbHRWRk1GYkZAzQU1DalRSY05zOVl5aE1tcjRMS3lXLURaVWNMOGZArWTVxS2hPQUVGVWxhbXZAyZA0p3azVKM2hBSEp3YlpR"
}
},
"next": "https://graph.facebook.com/v2.11/123928391023981/members?access_token=EAACEdEose0cBALBDrdgLyVOjzW4mz6G3d3Yj1fTGYqygVgYq0JCDZAi0zYsY90pSSQ9hQZCn3TdwfXIAiyoXH5oUYcA4hOcCI9jztkkUhbBv9tEQ3ZBEEuHpmkm3kmgvk1HNq5mo6BM0hz8XkOLVh3twIdz83KhB9SkqxuxHeFD9GWsQqjys6XTuL2315QZD&pretty=0&limit= 1500&after=QVFIUkFoU3lYR2tXc08adkg5OGhlbHRWYk1GYkZAzQU1DalRSY05zOVl5aQ1tcjRMS3lXLURaVWNMOGZArWTVxS2hPQUVGVWxhbXZAyZA0p3azVKM1hBSEp3YlpR"
}
Then follow this algorithm:
Make a count variable with a 0 value.
Count the objects in the data array of the latest response and add the count to the count variable.
If the latest response has the next property, make a request to the URL which is the next property value and return to the step 2. Otherwise you have finished, the count of members is the count variable value.
This way is not very good because the more members there are in the group the more queries are required. I would be better to parse the number of members from the group page HTML but I can't find reliable way to do it.
Update 2017.10.19: If the Facebook API response size is more then about 345KB, Facebook returns an error: Please reduce the amount of data you're asking for, then retry your request. It is about 1997 members. So you need to set the limit request parameter to 1500 not to face the error.
Update 2018.01.26: There is a way to get a count of members using a single request: https://stackoverflow.com/a/47783306/1118709
Update 2018.01.31: After 90 days from releasing Graph API v2.12 the request will require an access token of an admin of the group. Source: Graph API docs / v2.12 changelog / 90-day breaking changes
You should do it with an FQL query on the group_member table like:
SELECT uid FROM group_member WHERE gid = <group_id> limit 500 offset 500
Example here: Is it possible / how to get number of a particular Facebook Group members (even if number of them is 500+)?