I am confused with the keys and generally lost the idea, tell me how it is correct and easier to display the products from the community in vk

    2 answers 2

    The best recipe for displaying products on the site will be uploading them not through JavaScript, but in the language in which your site is written. For example, in PHP.

    1. Create a standalone application on the application creation page .
    2. Open the https://api.vk.com/oauth/authorize?client_id=123456789&scope=market,offline&response_type=token&v=5.59 link in your browser, replacing 123456789 with your application ID (you can find it in the Settings tab of the application). If you want to give the application more rights, for example, to make calls not only to product methods, but also to others, you will need to specify more rights in the scope parameter. See more about rights here .
    3. After you allow your application to access your account, the browser’s address bar changes: https://oauth.vk.com/blank.html#access_token=ea05c261301bfsdf416d9145ac1ee95f438cb2c87bb9212335f3ebed3eqwe7e8a458c3164567123aca59e1de&expires_in=0&user_id=1234567 In this example, your token is ea05c261301bfsdf416d9145ac1ee95f438cb2c87bb9212335f3ebed3eqwe7e8a458c3164567123aca59e1de .

    You now have an access_token, also known as a user access key, with which you can make requests to the API. For example, like this: https://api.vk.com/method/market.get?owner_id=-124527492&access_token=ea05c261301bfsdf416d9145ac1ee95f438cb2c87bb9212335f3ebed3eqwe7e8a458c3164567123aca59e1de&v=5.59 ?

    • Thank! all laid out on the shelves - Zero

    Once you have the javascript tag in question, I’ll assume that you are using the Open API or JavaScript SDK . The examples will be written in the Open API, but if you are working with the JavaScript SDK, then replace the VK.Api.call method with the VK.Api.call method in the example below.

     VK.Api.call('market.get', {'owner_id': -124527492}, function(data) { if (typeof data['error'] !== 'undefined') { alert('Произошла ошибка VK API #' + data['error']['error_code'] + ': ' + data['error']['error_msg']); return; } data['response']['items'].forEach(function(item) { $('body').append('<p>' + item['title'] + ' (' + item['price']['text'] + ')</p>'); $('body').append('<img src="' + item['thumb_photo'] + '" alt="' + item['title'] + '">'); $('body').append('<hr>'); }); }); 

    The JavaScript SDK is used in iFrame applications (including in "community applications"), and the Open API is used on regular websites. Please note that the market.get method does not work without user authorization, therefore, in the case of an iFrame application, you will need to request user access to the goods, and in the case of the Open API, you must authorize the site and also request access to the goods .

    But it would be more correct to do the unloading of goods not through JavaScript, but in the language in which your site is written. For example, in PHP.

    • And without authorization? There are options? Let the goods on the wall and receive from the wall? Or make an application? - Zero
    • Without authorization of your users, the most appropriate option will be to unload goods on the server, for example, in PHP. This approach will save you from the creation of bicycles and for the convenience of users, it will be the best and most transparent. In the comments, everything does not fit, so I will now write a separate answer to your question. - neluzhin