Ricardo
Ricardo

Reputation: 2943

How can I get the user first name from facebook in cloud code?

How can I get the user first name from facebook in cloud code? I can do it using objC and in the app, but I want from the server, cloud code. How can I send a facebook request from cloud code? do I have to use the access token saved in authData in any way? Thanks

Upvotes: 1

Views: 619

Answers (2)

Jaime Agudo
Jaime Agudo

Reputation: 8296

For those browsing this now that docs are getting out of synch after FB drop this was not officially supported as per https://groups.google.com/forum/#!topic/parse-developers/mw7qhHGIsOc

IMHO best bet ATM is to use the graph API directly. Within a Parse.Cloud function:

let access_token = request.user.get('authData').facebook.access_token
Parse.Cloud.httpRequest({
        url: 'https://graph.facebook.com/v2.8/' + path + '&access_token=' + access_token
    })
    .then(function(result) { 
        console.log(result)
    }, function(error) { 
        console.log(error)
    })

for the original question let path='me?fields=first_name' or FB_ID if not me

Upvotes: 1

Jesús Hurtado
Jesús Hurtado

Reputation: 295

It seems that you can use a graph search

FB.api('/me', function(response) {
  alert('Your name is ' + response.name);
});

But they don´t recommend you to get Facebook data of a user using the Parse Cloud

Check it out

https://www.parse.com/questions/get-user-info-from-facebook-javascript-sdk-after-login

Upvotes: 1

Related Questions