Spring Social VK(Vkontakte):如何获取用户相册 [英] Spring social vk (Vkontakte): How to fetch user photo albums

查看:323
本文介绍了Spring Social VK(Vkontakte):如何获取用户相册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一些春季社交项目整合到我的项目中,现在我正在寻找一种方法来从vk/vkontakte获取用户相册. 获取个人资料照片数据没有问题,因为我可以通过VKontakteProfile类获取它. 作为api https://vk.com/pages?oid=-17680044&p= getProfiles 提供了这样的功能,我正在搜索api方法,但找不到...

im trying to integrate some spring social projects into my project and now im searching for a way how to get users photo albums from vk/vkontakte. Getting the profile photo data is no problem as i can get it with the VKontakteProfile class. As the api https://vk.com/pages?oid=-17680044&p=getProfiles offers such function i was searching a api method but couldn't find...

推荐答案

要获取用户相册,您必须具有一个access_token,因为通常大多数uf用户都将其相册隐藏在未经授权的人群中.您可以通过使用您创建的应用或通过以下链接进行OAuth授权来获得它:

To get user albums you must have an access_token because typically most uf users hide their albums from not autorized people. You can get it by making OAuth-autorization with app created by you OR by this link:

https://oauth.vk.com/token?grant_type=password&client_id=2274003&client_secret=hHbZxrka2uZ6jB1inYsH&username=YOUT_ACCOUNTS_LOGIN&password=YOUR_ACCOUNT_PASSWORD

此链接由官方vk android应用程序使用,用于使"直接"自动化. 直接身份验证仅适用于ios,android和Windows Phone应用程序之类的官方应用程序.因此client_idclient_secret是来自android-application的数据.它是从反编译的应用程序中提取的.不要害怕:它永远不会改变.

This link uses by official vk android application to make "straight" autorization. Straight auth is allowed only to official apps like ios, android and windows phone app. So client_id and client_secret is data from android-application. It was extracted from decompiled app. Do not afraid: it will not be changed ever.

因此,您发出了GET请求,并且如果登录数据正确,则会得到access_token作为响应.

So, you made this GET request and got access_token in response if login data is correct.

然后您应该使用方法photos.getAlbums这样:

Then you should use method photos.getAlbums like this:

https://api.vk.com/method/photos.getAlbums.xml?owner_id=YOUR_PAGE_ID&access_token=YOUR_ACCESS_TOKEN

如您所见,URL包含".xml".因此,如果您希望响应具有JSON格式,只需从此URL中删除".xml"即可.但是我认为xml更易于解析.

As you can see, url contains ".xml". So if you want response to have JSON format just remove ".xml" from this url. But xml is more comfortable to parse I think.

下一步,如果以后需要获取相册照片,则应使用photos.get方法.要使用它,您需要相册识别号.响应您的上一个请求,此参数称为援助".

Next if you need to get albums photo later you should use method photos.get. To use it you need albums identification numbers. In response of your last request this parameter is called "aid".

您可以使用正则表达式从响应中获取这些参数,表达式应为<aid>(.*?)<\/aid>

You can use regular expressions to grab these parameters from response, expression should be <aid>(.*?)<\/aid>

因此,接下来您要请求从特定相册获取数据:

So next you making your request to get data from specific album:

https://api.vk.com/method/photos.get.xml?owner_id=YOUR_ACCOUNT_ID&album_id=PARSED_ALBUM_ID&access_token=YOUT_ACCESS_TOKEN

与"xml"响应格式相同的情况.因此,您将看到照片"对象列表,其中包含有关该图片的所有数据,例如它在相册中的ID,它在图片上的链接(大小不同),宽度,高度,描述,上传日期等.

The same situation with "xml" response format. So you will see the list of objects "photo" which contains all data about this picture like it's ID in album, it's link on pictures (with different sizes), it's width, height, description, upload date and others.

请随时从我这里获取有关VK API的任何帮助.

Feel free to get any help about VK API from me.

API拥有的所有方法的列表在这里: https://vk.com/dev/methods

The list of all methods that API has is here: https://vk.com/dev/methods

这篇关于Spring Social VK(Vkontakte):如何获取用户相册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆