bisrael / cordova-plugin-facebook

Cordova Plugin for iOS and Android Facebook SDK
MIT License
25 stars 21 forks source link

How can I get the user data? #13

Open ayaribrahim opened 8 years ago

arthurlataks commented 8 years ago

Using Graph Request. Path "me" can be used when there is currently authenticated user. If there is none - refer to the Facebook Graph API docs.

CordovaFacebook.graphRequest({
    path: '/me',
    params: { fields: 'email,id,first_name,last_name,gender,link,name' },
    onSuccess: function (userData) {
        console.log(userData)
    },
    onFailure: function (result) {
        if (result.error) {
            Error.log('error', 'There was an error in graph request:' + result.errorLocalized);
        }
    }
});
rwvalentine commented 8 years ago

@arthurlataks How would you post to user's feed or like on behalf of user?

rwvalentine commented 8 years ago

This worked:

        CordovaFacebook.graphRequest({
            path:  '/---userid---/feed',
            params: { access_token: '---useraccesstoken---', method: 'POST',  message: "test" },
            onSuccess: function (result) { 
              console.log(result); 
            },
            onFailure: function (result) {
                if (result.error) { alert('error', 'There was an error in graph request:' + result.errorLocalized); }
            }
        });
shtaif commented 7 years ago

Hi, thanks for the help, but all the rest of the methods and their arguments should really be documented in README as well, not just the .login and the .logout ones.

damianobarbati commented 7 years ago

@shtaif it's like the fields parameter is not sent: can you help with this one?

            window.CordovaFacebook.graphRequest({
                path:  '/me',
                params: {
                    access_token: accessToken,
                    fields: 'first_name,last_name',
                },
                onSuccess: result => resolve(result),
                onFailure: result => reject(result),
            });

The call runs fine but printing the result I see just "id" and "name" fields like the "fields" param was ignored and not passed through: how can I debug this?