问题
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