I am writing an application that needs to use the user data taken from the client social network VKontakte. I did authorize VKontakte.
VKSdk.initialize(sdkListener, String.valueOf(idVK), VKAccessToken.tokenFromSharedPreferences(this, sTokenKey));
And got AccessToken. As now I get the name and email user?
You can request email scope from user, then get email from access token:
String email = VKSdk.getAccessToken().email;
String userId = VKSdk.getAccessToken().userId;
//Get user info
VKApi.users().get().executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
VKApiUser user = ((VKList<VKApiUser>)response.parsedModel).get(0);
Log.d("User name", user.first_name + " " + user.last_name);
}
});
But remember, email is only available after first access request.
Old answer:
You can't get an email. This is not available. But you can get user name:
VKApi.users().get().executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
VKApiUser user = ((VKList<VKApiUser>)response.parsedModel).get(0);
Log.d("User name", user.first_name + " " + user.last_name);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With