-1

I am trying to get a ID and NAME of User's FRIEND by random with this code:

 // Acess Grantes of permissions code (not full (work))

function checkPerms(){
    var permsNeeded = ['email','public_profile','user_friends'];
//.... Continue of CheckPerms (  it works fine)

// this is User's Friend ID random ( no work) 
          FB.api(
        "/{user-id}/friends",
        function (response) {
          if (response && !response.error) {
            var random = Math.floor(Math.random()*response.data.length);
            console.log(random);
            /* handle the result */
          }
        }
    );
// this is user NAME (work)
FB.api("/me", function(res){
            uname = (res.name)?res.name : '';
            console.log(uname);
        }); 
// This is User Friend's NAME ( no work)
    FB.api("/"+uid1, function(res){
            fname = (res.name)?res.name : '';
            console.log(fname);
        });

I only get console of uname, not others. can you please tell me what's wrong in my code / or if I need any permission from facebook to acess the data of friend ID's and names.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
Mr.Samxo
  • 27
  • 7
  • You can only get friends that have granted user_friends permission to the app. Not all friends – WizKid Jun 17 '16 at 19:11
  • And how to get Who does not have granted this? Wich permission going to allow me to do so. and if it does need review for facebook administrators? – Mr.Samxo Jun 17 '16 at 19:15
  • You just need to ask the person to grant it – WizKid Jun 17 '16 at 19:37
  • I want to ask one user to access all their friend ID / PIC/ NAME So how that's possible then? – Mr.Samxo Jun 17 '16 at 19:50
  • Dis you read my first post. You can only get friends that has granted user_friends permission – WizKid Jun 17 '16 at 19:56
  • Yes but I know there is way to have acess one user';s friend Id/pic/name ( THOSE FRIENDS DOES NOT HAVE GRANTED ACESS) only 1 user has , so I use that user's friend picture to share on his content. Like:nametest.com – Mr.Samxo Jun 18 '16 at 00:59
  • I understand that with user_friends permission I can acess friends only if those friends also have installed the app, but how can I do without let them install it ? I mean if someone for example : John granted permision to my app, so I use his profile and then his friend's profile ( This friend does not have permission to my app) So? – Mr.Samxo Jun 18 '16 at 01:00
  • 1
    You can't. You can only get friends that granted permission – WizKid Jun 18 '16 at 06:38

2 Answers2

0

Since v2.0 of the Graph API, you can only access friends who authorized your App with the user_friends permission too, for privacy reasons.

There is a very detailed and complete answer about the issue in this thread: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
0

This is the code I use for saving the data.

function GetFBLoginStatus() {
        FB.getLoginStatus(function (response) {
            console.log(response);
            if (response.status === 'connected') {
                var accessToken = response.authResponse.accessToken;
                var email = response.authResponse.accessToken;
                FB.api('/me', { locale: 'en_US', fields: 'id, name, email' },
                    function (response) {
                        console.log(response.id);
                        console.log(response.name);
                        console.log(response.email);
                        alert("Funcion GetFB");

                        var id = document.getElementById("<%=HiddenField1.ClientID%>");
                        var nombreDePersona = document.getElementById("<%=HiddenField2.ClientID%>");
                        var email = document.getElementById("<%=HiddenField3.ClientID%>");

                        id.value = response.id;
                        nombreDePersona.value = response.name;
                        email.value = response.email;

                        __doPostBack("MyCall", "");
                }
            );
        } else if (response.status === 'not_authorized') {
            //login function
            alert('login first');
        } else {
            //login function
            alert('login first');
        }
    }, true);
    }

I call a c# method and pass the values to hidden fields.