Facebook API stops at 25 photos - facebook

I have tried using the limit parameter for selecting photos from albums on my facebook page. The javascript api just ignores the parameter and according to
https://developers.facebook.com/docs/graph-api/reference/photo/
This endpoint does not have any parameters. So I am trying to figure out how to return more than 25 photos for albums that contain more. Here is the part of my code that returns the photos
FB.api(
'/'+id+'/photos?limit=100',
'GET',
{"fields":"link,source"},
function(response) {
$(location).children().remove();
for ( var i = 0; i < response.data.length; i++) {
$(location).append('<li><img src="'+response.data[i].source+'"/></li>');
}
}
);
If anyone can help me figure out why and or how to get more than 25 results using the photos graph api that would be great!

Related

How do I paginate results from the Facebook SDK friends endpoint?

I'm using the Facebook SDK for JS to get a list of FB friends for a given FB user ID. Essentially, I make a request as follows:
FB.api(`/${fbUserId}/friends`, (response) => {
if (response && response.data) {
fbFriends = fbFriends.concat(response.data);
}
if (response && response.paging && response.paging.cursors && response.paging.cursors.after) {
// Recurse through.
}
});
I can get the first set of results, which contains 13 friends, and can also see that there are 200+ friends total, but the problem I'm having is when I try to recurse through and get all 200+ friends.
Specifically, I'm referencing the following two pages:
https://developers.facebook.com/docs/graph-api/using-graph-api/#cursors
https://developers.facebook.com/docs/graph-api/reference/user/friends/
Trying to put things together from those two pages, I thought that a request URL like the following would work:
const afterParam = response.paging.cursors.after ? `&after=${response.paging.cursors.after}` : '';
FB.api(`/${fbUserId}/friends${afterParam}`, (response) => {
...
But it doesn't return any results. I am console-logging response.paging.cursors.after, and I'm sure it's set appropriately from the first API call, but it's not returning any more friends. I always get back an empty array for response.data.
What am I doing wrong? Admittedly, the FB API docs seem a bit sparse, and I don't see anywhere where they specifically show how to go through pages of results for the friends API endpoint, but I'm obviously missing something. Thank you.

Facebook Graph API - How to avoid request limits when accessing a user's photos?

I need to fetch user photos and albums using the Facebook Graph API.
As far as I understand (while reading the docs) this is a two step procedure, 1. fetching the id for each photo from the photos edge, 2. using the returned array of ids, fetching individual photo nodes.
Fetching individual photo nodes could mean hundreds of requests/s, while having a lot of photos on my profile I have hit the app request limits after a few minutes of testing.
Is there maybe a way to fetch all photos at once (or in fewer requests), in order to avoid request limits?
example implementation:
...
var photos = [];
function fetchPhotos(){
fetch('https://graph.facebook.com/v3.1/me/photos?type=uploaded&access_token=' + accesstoken, {
method: 'GET'
})
.then(photos => photos.json())
.catch(error => console.error('Error:', error))
.then(photos => {
this.fetchPhoto(photos);
});
}
function fetchPhoto(photos){
for(var i=0; i < photos.data.length; i++){
fetch('https://graph.facebook.com/v3.1/' + photos.data[i].id + '?fields=link,width,height&access_token=' + accesstoken, {
method: 'GET'
})
.then(photo => photo.json())
.catch(error => console.error('Error:', error))
.then(photo => {
photos.push(photo);
});
}
}
...
Thanks!
You can already get a list with all the fields with one call:
https://graph.facebook.com/v3.1/me/photos?fields=link,width,height&access_token=...
Side Note: If that is client code, why not use the official JS SDK? That way, you don´t need to deal with the Access Token, it gets added automatically.

Facebook api not returning friends contact info

In my contacts manager app, I need to have an option to import contacts from facebook. Im using hello.js This is the function
function getFriends(network, path){
var list = document.getElementById('list');
list.innerHTML = '';
// login
hello.login( network, {scope:'friends'}, function(auth){
if(!auth||auth.error){
console.log("Signin aborted");
return;
}
// Get the friends
// using path, me/friends or me/contacts
hello( network ).api( path , function responseHandler(r){
for(var i=0;i<r.data.length;i++){
var o = r.data[i];
var li = document.createElement('li');
var ph = "";
if(o.gd$phoneNumber != undefined)
{
for (var j = 0; j <= o.gd$phoneNumber.length; j++ ) {
if(o.gd$phoneNumber[j] != undefined)
{
//console.log(o.gd$phoneNumber[j].$t);
ph += o.gd$phoneNumber[j].$t +'<br>';
}
};
}
li.innerHTML = o.name + (o.thumbnail?" <img src="+o.thumbnail+" />":'') +' Phone : '+ph;
list.appendChild(li);
};
});
});
}
The function is invoked by getFriends('facebook','me/friends') .This only returns the count of friends like this
{
"data": [
],
"summary": {
"total_count": 1076
}
}
but by using getFriends('facebook','me/taggable_friends'), I'm getting the name and image of the friends but not any email id or contact number.
Can anyone figure out the issue ?
/me/taggable_friends is ONLY for getting tagging tokens (you don´t get User IDs), and ONLY for tagging your friends (in status posts, for example).
/me/friends only returns friends who authorized your App too, that´s intentional. Users who don´t use your App don´t show up for privacy reasons.
That being said, even if you would be able to get ALL friends, you can´t get any details like email and especially not a contact number. You can´t even get the phone number from the authorized User.
Detailed information can be found in the changelog: https://developers.facebook.com/docs/apps/changelog

Accessing Facebook data through the Facebook Graph API and restFB

When I access Facebook through the Graph API I get only very few entries. For instance if I access the Galaxy S4 fan page through the Graph API I see only four entries:
https://graph.facebook.com/412437702197294/comments/
if I access it through restFB I only get 2:
FacebookClient publicOnlyFacebookClient = new DefaultFacebookClient();
Page page = publicOnlyFacebookClient.fetchObject("GalaxySFour", Page.class);
JsonObject galaxySFourID = publicOnlyFacebookClient.fetchObject("GalaxySFOUR", JsonObject.class);
JsonObject galaxySFour = publicOnlyFacebookClient.fetchObject(galaxySFourID.getString("cover_id") + "/comments", JsonObject.class);
Vector<String> comments = new Vector<String>();
for(int i = 0; i < galaxySFour.length(); i++) {
comments.add("Message: " + galaxySFour.getJsonArray("data").getJsonObject(i).getString("created_time") + ": " + galaxySFour.getJsonArray("data").getJsonObject(i).getString("message"));
}
I'm aware that I cannot get all data, but I didn't expect to get so little. Is there anyway to get more data?
Access via this link : http://facebook.com/412437702197294,
there are only 4 comments. So, https://graph.facebook.com/412437702197294/comments/ return 4 comments is right.
By default, when retrieving data via Facebook Graph API, you only get 20 results.
You can use limit to get more data, such as:
http://facebook.com/412437702197294?limit=500
The maximum limit is 5000.

How to get the post of the user using javascript sdk

I am creating my first facebook app using javascript sdk. In that i can able to post to the user's wall using(FB.api('me/feed', 'post', )).
Now what I need is, when the user accessing my app, it has to show (or list) the post of that user. The code is
FB.api('/me/posts', function(response) {
for (var i=0, l=response.length; i<l; i++) {
var post = response[i];
alert('The value of post is:'+post);
if (post.message) {
alert('Message: ' + post.message);
} else if (post.attachment && post.attachment.name) {
alert('Attachment: ' + post.attachment.name);
}
}
});
But it is not working. If I remove l=response.length and change the condition as i<5 it is going inside the loop but it gives the value of post is undefined.
I didn't get why it is returning as undefined. It returns same for post.message also.
I am getting the access_token of the user also.
If I want to get the post of my user what code i have to use. Can anyone help me in this.
Thanks in advance
You can use the Facebook Graph API Explorer to better understand what data you will be receiving. https://developers.facebook.com/tools/explorer/
You should have l=response.data.length and var post = response.data[i];. Also, some posts will not have a "message", but will have a "story" instead (mainly posts like "Joe Smith and Tom Someone are now friends."). Make sure you also have the appropriate permissions (e.g. user_status) for the information you're trying to receive.