cordova-plugin-facebook icon indicating copy to clipboard operation
cordova-plugin-facebook copied to clipboard

How can I get the user data?

Open ayaribrahim opened this issue 8 years ago • 5 comments

ayaribrahim avatar Jun 03 '16 16:06 ayaribrahim

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);
        }
    }
});

arthurlataks avatar Jul 13 '16 13:07 arthurlataks

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

rwvalentine avatar Sep 06 '16 03:09 rwvalentine

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); }
            }
        });

rwvalentine avatar Sep 06 '16 03:09 rwvalentine

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.

shtaif avatar Nov 08 '16 19:11 shtaif

@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?

damianobarbati avatar Sep 12 '17 15:09 damianobarbati