M
M
Max Payne2015-04-17 22:46:19
PHP
Max Payne, 2015-04-17 22:46:19

Why doesn't uploading photos to VK work?

I am using the following code:

<?php
print_r(upload('tmp_img.jpg','токен');
function upload($img,$token) {
    ($getUploadServer = curl('https://api.vk.com/method/photos.getWallUploadServer?access_token='.$token));
    ($getUploadServer = json_decode($getUploadServer, true));
    ( $uploadUrl       = $getUploadServer['response']['upload_url']);
    ( $uploadPhoto = curl($uploadUrl, array('photo' => '@'.$img)));
    ($uploadJson  = json_decode($uploadPhoto, true));
    ($savePhoto = curl('https://api.vk.com/method/photos.saveWallPhoto?access_token='.$token.'&server='.$uploadJson['server'].'&photo='.$uploadJson['photo'].'&hash='.$uploadJson['hash']));
 
        return $savePhoto;
}
 
function curl( $url, $post = null )
{
    $ch = curl_init( $url );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
        if($post != null)
        {
            curl_setopt( $ch, CURLOPT_POST, true );
            curl_setopt( $ch, CURLOPT_POSTFIELDS, $post );
        }
    $response = curl_exec( $ch );
    curl_close( $ch );
    return $response;
}
?>

In response I get:
{"error":{"error_code":100,"error_msg":"One of the parameters specified was missing or invalid: photos_list is invalid","request_params":[{"key":"oauth","value":"1"},{"key":"method","value":"photos.saveWallPhoto"},{"key":"server","value":"623817"},{"key":"photo","value":"[]"},{"key":"hash","value":"hash"}]}}

Where is the mistake? The file tmp_img.jpg exists .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2015-04-18
@Sanasol

error between two api calls.
Checks should be put everywhere and see what gives VK

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question