D
D
Dmaw2021-01-05 14:17:56
PHP
Dmaw, 2021-01-05 14:17:56

Posting VK API method wall.post, why no rights?

Good afternoon!
The task is to post articles from the site to the VK group.
I am guided by these pages:
https://vk.com/dev/authcode_flow_user
https://vk.com/dev/wall.post

1) I am creating a Standalone application.

2) I follow the authorization link:

https://oauth.vk.com/authorize?client_id=123456789&display=page&redirect_uri=https://сайт.ru/vk/callback.php&scope=offline,groups,wall&response_type=code&v=5.126

In the answer I receive the code, I copy it.

3) Follow the link to get a token:
https://oauth.vk.com/access_token?client_id=123456789&client_secret=секретный_код_приложения&redirect_uri=https://сайт.ru/vk/callback.php&code=ранее_полученный_код

In response, I receive a token, copy it.

4) Now I'm trying to create a post in a group:
$text = 'Тест-пост в ВК с сайта';

$a = [
    'owner_id' => '-1234567', // id группы
    'user_id' => '123456789', // id приложения	  
    'access_token' => '123456789123456789123456789123456789123456789123456789',
    'v' => '5.126',
    'message' => urlencode($text),
    ];

$json = file_get_contents('https://api.vk.com/method/wall.post?'.http_build_query($a));

$a = json_decode($json, true);
echo '<pre>'; print_r($a); echo '</pre>';

The response is:
[error_code] => 15
[error_msg] => Access denied: no access to call this method
What am I doing wrong?
I tried to create an application with the "Site" type, it did not help.
I tried to get a token with rights to the group, it did not help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
a, 2021-01-05
@Dmaw

You may be getting the token incorrectly.
Try to get it from https://vkhost.github.io/
Go to [Settings].
Token type - [Community]
Application ID - [ID]
Community ID - [ID]
Rights - select the rights you need.
After you click on the receive button, you will be redirected to https://oauth.vk.com/ ........

B
Belarus007, 2021-01-05
@Belarus007

try replacing redirect_uri with https://oauth.vk.com/blank.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question