4

Good day. The question on the use of library VK. How to get a profile picture, using VKSDK\ Can not find the right information on the Internet.

        

greg-449
  • 109,219
  • 232
  • 102
  • 145
user3366290
  • 447
  • 1
  • 5
  • 7

3 Answers3

7

In your request you need to specify one of the following fields: photo_50 or photo_100 or photo_200:

VKRequest yourRequest = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS,"photo_50"))

After that when you will retrieve users data you can get photo_50:

yourRequest.executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
    super.onComplete(response);

    VKUsersArray usersArray = (VKUsersArray) response.parsedModel;

    for (VKApiUserFull userFull : usersArray) {
          Log.i(TAG, "Avatar image URL: " + userFull.photo_50);            
        }
    }
}
Community
  • 1
  • 1
user3760402
  • 81
  • 1
  • 3
  • 2
    But instead of get(VKApiConst.FIELDS, "photo_50") you should use VKRequest yourRequest = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS, "photo_50")); – SERG Mar 30 '15 at 07:32
1

For android apps:

You get the profile photo by sending a request like this:

    https://api.vk.com/method/users.get?user_id=5337911&v=5.23&fields=photo_50

For iframe applications:

You should use users.get method of VK.api

    VK.api('users.get', {
        user_ids: id,
        fields: "photo_50"
    }, function(data) {
        photo_50 = data.response[0].photo_50;
    });

If you don't know what is VK.api then you should read about Javascript SDK

Fancy John
  • 38,140
  • 3
  • 27
  • 27
0

Well my friend I fix this problem with my own solution like this: And this works for 100%

public class RootVKAccount
{
    public List<VKAccount> response { get; set; }
}

[JsonObject("response")]
public class VKAccount
{
    [JsonProperty("photo_200")]
    public string UserImgUrl { get; set; }
}

HttpWebRequest request = WebRequest.Create($@"https://api.vk.com/method/users.get?owner_id={UserId}&fields=photo_200&access_token={Token}&v=5.92") as HttpWebRequest;
    HttpWebResponse respons = request.GetResponse() as HttpWebResponse;

Stream jsonStream = respons.GetResponseStream();
StreamReader r = new StreamReader(jsonStream);
string jsonStr = r.ReadToEnd();
r.Dispose();
var obj = JsonConvert.DeserializeObject<RootVKAccount>(jsonStr);

string uri = obj.response[0].UserImgUrl;
new WebClient().DownloadFile(uri, avatarFullPAth);
Elletlar
  • 3,136
  • 7
  • 32
  • 38
David Melkumyan
  • 199
  • 1
  • 4