0

I'm new to Facebook API and I would like to get information on the friends the logged user has. At first I had default privileges configured so all I got was just the names.
Once I've requested for additional privileges, it gave me a 'paging' object... But I have no idea of what am I suppose to do with it.
For some reason I wasn't able to find anything useful with Google, so here I am.

Here is what I have so far:

index.html

<script src="http://connect.facebook.net/en_US/all.js"></script>
<script src="script.js"></script>
<script language="javascript" type="text/javascript">
        FB.init({
            appId: '118236041675713',
            status: true,
            cookie: true,
            xfbml: true
        });  
</script>
<fb:login-button perms="email,user_birthday" autologoutlink="true">

script.js

$(document).ready(function() {
        FB.login(function(response) {
           if (response.authResponse) {
              FB.api("/me/friends", {fields: 'name,id,birthday'}, function(res) {
                 console.log(res);
              });
           }
        });
});

SOLUTION: Additional info can be received from the next/previous properties. Important note: For some reason the jQuery $.get does work. So I had to use $.ajax:

$(document).ready(function() {
            FB.login(function(response) {
               if (response.authResponse) {
                  FB.api("/me/friends", {fields: 'name,id,birthday'}, function(res) {
                     var next = res.pages.next;
                     $.ajax({
                url: next,
                success: function(data) { alert(data) },
                dataType: 'html'
              });
               }
            });
    });
thedp
  • 8,350
  • 16
  • 53
  • 95
  • 1
    The paging object contains the query to make to retrieve the next and previous page of results for the query you just made (if there are any) – Igy Dec 15 '12 at 18:52

1 Answers1

1

The paging object will have 2 properties.

paging.next - this contains the url to the graph call that will return the next page of results

paging.previous - same but for previous page in results

Jason Reeves
  • 1,716
  • 1
  • 10
  • 13
  • How should I call it, with a simple ajax request? – thedp Dec 15 '12 at 19:00
  • there are several way to call it depending on your app, but yes... ajax will work. – Jason Reeves Dec 15 '12 at 19:03
  • I see people mentioning server side scripts and shortening the urls so that you can use them with the regular js lib. – Jason Reeves Dec 15 '12 at 19:08
  • My app is pure client-side. Is the paging method the only way I have to receive information from Facebook? It seems like a really bad way to implement an API. – thedp Dec 15 '12 at 19:14
  • I've tried to use the `next` for the ajax request and got a Bad Request Error (400). `$.post(response.paging.next, {}, function(data) { console.log('PAGE: ', data); }, "json");` – thedp Dec 15 '12 at 19:20
  • yes you can also use limit, offset or until and since in your calls. [See This Page](https://developers.facebook.com/docs/reference/api/pagination/) – Jason Reeves Dec 15 '12 at 19:26
  • this is my next: `https://graph.facebook.com/522839538/friends?fields=name,id,location,birthday&access_token=AAABriPlDg8EBAImUfrZBWZAr8ZCHlBscrCAsmQBFweKxYDSkAJteMfML8z4jT0sneuzIuQJmrDKvH2b7GrARg9j0dxFkNwanptgMQ1IyAZDZD&limit=5000&offset=5000&__after_id=100004534507341` Why do I get a bad request? Maybe my setting are wrong? – thedp Dec 15 '12 at 19:36
  • wow.. so you are setting limit and offset to 5000. Basically you are say give me 5000 friends starting at friend 5000 (# 5001-10,000)... ergo bad request. – Jason Reeves Dec 15 '12 at 19:42
  • Hmm weird. As you can see in my example and the comment with the ajax request for the next page, I didn't set those values. Am I missing something here? – thedp Dec 15 '12 at 19:45
  • do you look at the page link that @StéphaneBruckert shared as well? It has examples of using JS and paging. – Jason Reeves Dec 15 '12 at 19:48
  • Just tried it. Still getting the same Bad Request. I've set the `offset: 0`, and `limit: 400` for 400 friends. Can you place have a look at the way I make the AJAX call, a couple comments back? Thank you. – thedp Dec 15 '12 at 20:08
  • my suggestion is that __after_id and offset don't match. I wouldn't use after_id... just use limit and offset. – Jason Reeves Dec 15 '12 at 20:14
  • That's what I do. I've setup a small example online: http://duskcloud.com/_test/index.html – thedp Dec 15 '12 at 20:55