Answer the question
In order to leave comments, you need to log in
VKontakte API method messages.get. What am I doing wrong?
Good day to all. This is my first time dealing with social media APIs. I'm trying to use the VK API. In this case, the messages.get method. Got APP_ID wrote code with client authorization and messages.get request:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="//vk.com/js/api/openapi.js" type="text/javascript"></script>
</head>
<body>
<div id="vk_api_transport"></div>
<div id="login_button" onclick="VK.Auth.login(authInfo);"></div>
<script type="text/javascript">
window.vkAsyncInit = function() {
VK.init({
apiId: APP_ID
});
};
function authInfo(response) {
console.log(response)
if (response.session) {
alert('user: ' + response.session.mid);
} else {
alert('not auth');
}
}
VK.Auth.getLoginStatus(authInfo);
VK.UI.button('login_button');
VK.Api.call('messages.get', {
fields: 'messages'
}, function(data) {
console.log(data)
});
setTimeout(function() {
var el = document.createElement("script");
el.type = "text/javascript";
el.src = "//vk.com/js/api/openapi.js";
el.async = true;
document.getElementById("vk_api_transport").appendChild(el);
}, 0);
</script>
</body>
</html>
Access denied: no access to call this method
Answer the question
In order to leave comments, you need to log in
The messages .*
methods can only be accessed by standalone applications. These are applications that work without the help of a browser. For example, clients (official VK apps, Kate Mobile, Snapster, etc.). And you have an application type of "website".
There's nothing you can do about it, and you won't be able to get the Open API to work with messages. The only way out is to throw the user on the page for obtaining a token in your standalone application and ask them to copy it into a form on your site, and then make requests from the server with this token. But this has a bad effect on UX, if only because on the page from where the user will copy this very token, it is written in bold that copying the token may be unsafe.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question