0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
moonvader
  • 19,761
  • 18
  • 67
  • 116

2 Answers2

1

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")

})
moonvader
  • 19,761
  • 18
  • 67
  • 116
0

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.

GRiMe2D
  • 654
  • 1
  • 10
  • 22
  • var user = VKSdk.accessToken().localUser.first_name print(user) this code breaks "fatal error: unexpectedly found nil while unwrapping an Optional value" – moonvader Apr 12 '16 at 15:47
  • @moonvader VKSdk.accessToken().localUser is nil if VK app is not installed. – Dongjin Suh Dec 08 '16 at 06:09