Actually getting the user information and saving into a variable

124 views Asked by At

So, I have the following code on my site:

    if ( kik.hasPermission() ) {
        // do something
    } else {
        kik.getUser(function (user) {
            if ( !user ) {
                // error
            } else {
                typeof user.username;  // 'string'
                typeof user.fullName;  // 'string'
                typeof user.firstName; // 'string'
                typeof user.lastName;  // 'string'
                typeof user.pic;       // 'string'
                typeof user.thumbnail; // 'string'

                // set them ^ to vars here
            }
        });
    }

But I would like to set the data (user.username, etc.) into variables. I can't seem to work it out. All help is appreciated.

1

There are 1 answers

0
Jakob Abfalter On

The user paramter is an object containing the data you need. You can access and store the data like this

var username = user.username;
var fullName = user.fullName;
...

Be aware that user.pic and user.thumbnail are links to the images. If you want to store the image data you have to fetch it from the link first.