Get VK user avatar in Swift

1.1k views Asked by At

I know how to get user email address in vkSdkAccessAuthorizationFinishedWithResult method. How can I get his avatar image and other profile info?

I assume that i need to use VKRequest for this. Unfortunately i found no swift documentation for VK iOS SDK.

2

There are 2 answers

0
moonvader On BEST ANSWER

Ok, i finally found solution - you need to add this code inside vkSdkAccessAuthorizationFinishedWithResult method

let request:VKRequest = VKRequest(method: "users.get", andParameters: ["fields":"photo_50", "bdate"], andHttpMethod: "GET" )

request.executeWithResultBlock({ response in
       print(response.json)
    }, errorBlock: {
        (error) -> Void in
        print("error")

})
2
GRiMe2D On

Class VKAccessToken contains localUser property. You can access user profile info (including name, id) like this:

VKSdk.accessToken().localUser  

VKUser class has fields like photo_max, photo_50, ... photo_max_orig which contain urls for images.