VK Web API (simple)

不打扰是莪最后的温柔 提交于 2020-01-25 12:29:12

问题


I would like to call the method "photos.get" and retrieve photos from a VK community.The problem is that I am unable to view the oid i.e owner_id( one of the parameters required for the request) when I visit the URL. For example, when I browse a certain community, I end up getting a URL like "http://vk.com/picsa".Instead of this picsa, I require a number that can be passed in as an argument. How do I get the owner_id instead from the URL?


回答1:


You can use groups.getById API method. It does not require any authentication:

https://api.vk.com/method/groups.getById?group_ids=picsa

You will get the default group entity in JSON format:

{
    "response": [
        {
            "gid": 37460919, 
            "name": "AMERICA", 
            "screen_name": "picsa", 
            "is_closed": 0, 
            "type": "page", 
            // photos of different size go here
        }
    ]
}

Now, you can extract the community's ID (gid) and will be able to use it in other API requests. You can get information about several communities at the same time - you need to enumarate them with commas (/method/groups.getById?group_ids=picsa,othergroup,somename).

When you work with photos.get method, keep in mind, that VK uses negative ID values for communities and pages.

For example,
/method/photos.get?owner_id=123456789 means "photos of user 123456789" and
/method/photos.get?owner_id=-123456 means "photos of community 123456".




回答2:


Other way to get group id when there is no it in group link is to click on post date of any post on the wall

And in the address line you will see link like

https://vk.com/picsa?w=wall-37460919_47702

So 37460919 is group id you need



来源:https://stackoverflow.com/questions/31844144/vk-web-api-simple

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