F
F
fomenko_alexandr2017-01-09 20:03:55
PHP
fomenko_alexandr, 2017-01-09 20:03:55

How to upload photo vk api?

Hello masters.
Please tell me what kind of trouble is happening with api vk. The problem appears when trying to upload a photo to a user's or group's wall. Neither there nor there it is even possible to get the address for uploading an image (using the photos.getWallUploadServer method). I get error 15 (access error) all the time. Although it is strange that when I receive a token, I make a request for access to the wall, photos.
I get the token like this:

$url = 'https://oauth.vk.com/authorize';
$params = [
    'client_id'     => CLIENT_ID,
    'redirect_uri'  => 'https://oauth.vk.com/blank.html',
    'response_type' => 'token',
    'scope'         => 'status,wall,groups,offline,friends'
];
$url = $url.'?'.http_build_query($params);

echo '<a href="'. $url .'">Получить токен</a>';

Then I copy the received token, and already use it in requests.
But requests to get a server to download do not go through, here is my method
public function wallPhotosUpload() {
        $url = 'https://api.vk.com/method/photos.getUploadServer?';

        $params = [
            'group_id'      => $this->settings['group_id'],

            'access_token'  => $this->settings['token'],
            'v'             => '5.61',
        ];

        $url .= http_build_query($params);

        $result = file_get_contents($url);

        self::print_arr($result);
    }

I would be very grateful for a hint. Already tired of this problem
. I get an error like:
{"error":{"error_code":15,"error_msg":"Access denied: no access to call this method","request_params":[{"key":"oauth" ,"value":"1"},{"key":"method","value":"photos.getUploadServer"},{"key":"group_id","value":"78845789"},{" key":"v","value":"5.61"}]}}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
imdeveloper, 2017-01-09
@link_web

The method is available only to standalone applications
Or check if there are permissions https://vk.com/dev/account.getAppPermissions
If not, then you need to get it in scope when creating a token

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question