Developers Manual > SDK Integration > Facebook > Facebook API References in JavaScript > Facebook-getUserId

.getUserId()

The user's Facebook user ID, when a user is logged in and has authorized your app, or an empty string if not.

Example

1
2
3
4
5
6
7
8
var facebook = plugin.FacebookAgent.getInstance();
var userid = facebook.getUserId();
    if (userid){
        cc.log("User ID: " + userid);
    } else {
        cc.log("No valid User ID for the current user");
    }
});

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.