Capture data from Facebook users

Asked

Viewed 6,160 times

5

I am trying to collect with JAVASCRIPT/JQUERY some data from specific users that are not part of my friends list. I’d like to capture dice as: likes, friends, posts and groups.

I did some tests and saw no difference in being logged in or not on Facebook. The result is almost always JSON emptiness:

{
    data: [ ]
}

In some cases returns the correct data, but most apply in the case of empty.

A specific case occurs with friends:

{
    error: {
        message: "Unsupported operation",
        type: "FacebookApiException",
        code: 100
    }
}

Tests are done via the url:

https://graph.facebook.com/{user-id}/{edges}?access_token={access_token}

Where:

{user-id} = user id (Mine is 100002309392122);

{edges} = data that I want to collect said at the beginning of the question and that are listed in facebook documentation.

{access_token} = is the access key the API needs to take the data.

The token access was generated by me via an application I created only to generate it. Concatenating the application ID with the pipe character and then with the App Secret managed the token.

I wanted to change that scenario of "JSON empty". Am I doing something wrong? Is there no way to get this data? #How do?

1 answer

6


You are making a little mess with the access token.

This access_token is generated when the user explicitly authorizes his application to access the requested data.

To get the user’s data it is necessary that they access the page in question and authorize the app. I do so:

/*Esta função verifica se o usuário está logado no facebook. 
Se não estiver ele abre a janelinha de login*/
    function initFacebook() {
      FB.getLoginStatus(function(response) {
        if (response.status !== fbConnected) {
          loginFacebook(); 
        }
      });  
    }

/*Esta função vai recuperar tudo que você solicitou do usuário.*/
function carregarInformacoes() {
  FB.getLoginStatus(function(response) {
    if (response.status === fbConnected) {
      FB.api('/me', {}, function(response) {
        /*Response tem tudo que você solicitou, inclusive o access_token.*/
      });
    } else if (response.status === fbNotAuthorized) {
      loginFacebook(); 
    } else {
      loginFacebook();          
    }
  });  
}

/*Esta função pede permissão de acesso aos dados. Ela que no fim das contas vai gerar o access_token*/
function loginFacebook() {
  FB.login(function(response) {
    if (response.authResponse) {
      initFacebook();
    }       
  }, {scope: 'email, user_photos, friends_about_me, read_friendlists, user_education_history, user_groups, user_interests, user_likes, friends_likes, user_work_history, user_online_presence' });
}

Note that in loading instructions I use the path /me. This is done this way to get the data from the current user. Once authorized you can save the access_token in a life database.

After that you can use the approach you are trying to.

  • 1

    That’s it. : ) That’s it another issue have some examples of how to consult Likes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.