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.
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);
}
}
}
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
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);