Search code examples
windowswindows-phone-8vk

VK Web API (simple)


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?


Solution

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