VK Web API(简单) [英] VK Web API (simple)
问题描述
我想调用方法photos.get"并从VK社区检索照片.问题是我在访问网址.例如,当我浏览某个社区时,我最终会得到一个类似http://vk.com/picsa".我需要一个可以作为参数传入的数字,而不是这个 picsa.如何从 URL 中获取 owner_id?
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?
推荐答案
您可以使用 groups.getById
API 方法.它不需要任何身份验证:
You can use groups.getById
API method. It does not require any authentication:
https://api.vk.com/method/groups.getById?group_ids=picsa
您将获得 JSON 格式的默认组实体:
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
}
]
}
现在,您可以提取社区 ID (gid
) 并将能够在其他 API 请求中使用它.您可以同时获取有关多个社区的信息 - 您需要用逗号对它们进行枚举(/method/groups.getById?group_ids=picsa,othergroup,somename
).
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
).
当您使用 photos.get
方法时,请记住,VK 使用社区和页面的否定 ID 值.
When you work with photos.get
method, keep in mind, that VK uses negative ID values for communities and pages.
例如,/method/photos.get?owner_id=123456789
表示用户 123456789 的照片"和/method/photos.get?owner_id=-123456
表示社区 123456 的照片".
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".
这篇关于VK Web API(简单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!