简体   繁体   中英

Get user ID from phonegap facebook login

I am trying to allow a user to upload photos to my server after they login to my system with their facebook credentials. I am using the phonegap facebook plugin for android. How can I get their unique user ID from the facebook SDK? And should I use the javascript SDK or the Android SDK?

Thanks!

after u call FB.init....u have to call FB.login function and in the response of fb.login u will get the user id of person logged in...

the code for FB.login is

FB.login(function(response) {
                if (response.authResponse) {
                    alert('logged in');
                    fbId = response.authResponse.userId;
                     alert("user id is "+fbId);
                } else {
                    alert('not logged in');
                }
            }, {
                scope : "email"
            });

If anyone is curious this is how you do it after initializing the facebook javascript SDK:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM