我通过使用以下URL授权用户来获得令牌:
const fetch = require('node-fetch');
const VK_CLIENT_ID = '1231231';
const photos = 4;
const wall = 8192;
const offline = 65536;
const scope = offline + wall + photos;
const URL = `https://oauth.vk.com/authorize?client_id=${VK_CLIENT_ID}&display=popup&redirect_uri=http://example.com/auth/vk&scope=${scope}&response_type=token&v=5.78`;
const accessToken = '...';
const ownerID = '212121212';
fetch(
`https://api.vk.com/method/wall.post?v=5.78&message=test_api&owner_id=${ownerID}&access_token=${accessToken}`
)
.then(res => res.text())
.then(body => console.log(body));
错误:
{
error: {
error_code: 15,
error_msg: "Access denied: no access to call this method",
request_params: [
{ key: "oauth", value: "1" },
{ key: "method", value: "wall.post" },
{ key: "v", value: "5.78" },
{ key: "message", value: "test_api" },
{ key: "owner_id", value: "184591202" }
]
}
}
答案 0 :(得分:0)
我找到了原因。无法使用此API方法。您需要一个独立的VK应用程序(用于桌面或移动应用程序),然后用户需要批准在墙上发布。
查看此VK API, access denied for post on wall of a community, fail WALL Permissions