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.
在您的请求中,您需要指定以下字段之一:photo_50 或 photo_100 或 photo_200:
VKRequest yourRequest = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS,"photo_50"))
之后,当您检索用户数据时,您可以获得 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);
}
}
}
对于安卓应用:
您可以通过发送如下请求来获取个人资料照片:
https://api.vk.com/method/users.get?user_id=5337911&v=5.23&fields=photo_50
对于 iframe 应用程序:
你应该使用users.get
的方法VK.api
VK.api('users.get', {
user_ids: id,
fields: "photo_50"
}, function(data) {
photo_50 = data.response[0].photo_50;
});
如果您不知道是什么,VK.api
那么您应该阅读有关Javascript SDK的信息
好吧,我的朋友,我用自己的解决方案解决了这个问题:这适用于 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);