Unable to get user id from facebook javascript login api

I am using the facegap plugin for facebook and facebook javascript api. here is my code

FB.init({ appId: "xxxxxxxxxxxxxxx", status: true, oauth :true, nativeInterface: CDV.FB, //channelURL : 'www', // Channel File cookie: true, //useCachedDialogs: false, xfbml: true }); FB.login(function(response) { if (response.authResponse) { alert(response.authResponse.userID); // literally shows three dots FB.api('/me', function(me){ if (me.id) { alert(me.id); // this works } }); } }, { scope: "email" }); 

I can get accessToken from authResponse .... its long string. but the userID field is literally "...". I can get the user ID by making an extra trip to the server with another call to the graph API to get /me , but that seems wasteful.

+4
source share
2 answers

[In the interest of OP] You can get the user ID in the client by adding an additional call to the server when you started showing. Here is the correct code:

  FB.api('/me', function(me){ if (me.id) { var facebook_userid = me.id; alert(facebook_userid); } }); 

This does not explain why the userID field is "..." in the input response object. But this is a workaround.

+6
source

I posted a bug on github ( https://github.com/davejohnson/phonegap-plugin-facebook-connect/issues/151 ) because it seems to be a β€œfeature” of the plugin. Not sure if the problem is with sdk on facebook iOS (not transferring this data from FB) or in the plugin (not transferring this data at JS level).

+1
source

Source: https://habr.com/ru/post/1413745/


All Articles