Spring social vk (Vkontakte): How to fetch user photo albums

时间秒杀一切 提交于 2019-12-29 09:57:13

问题


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...


回答1:


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

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.

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

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

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.

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

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

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.

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

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




回答2:


As far as I know, VK provides API for getting user albums.

photos.getAlbums API method stands for this function.

For example,
https://api.vk.com/method/photos.getAlbums/?owner_id=5369654&access_token=your_access_token

It works for me. Read more about it here:
https://vk.com/dev.php?method=methods#/dev/photos.getAlbums



来源:https://stackoverflow.com/questions/31912670/spring-social-vk-vkontakte-how-to-fetch-user-photo-albums

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!