O
O
Outoverlay2016-02-24 21:38:34
PHP
Outoverlay, 2016-02-24 21:38:34

Uploading photos to the VK server?

There is a script for uploading photos to the server, but due to the fact that the script itself is outdated, it cannot be used.
Now I'm suffering, I'm suffering, then I get error 129, then erro 100:

$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$img = "1.png";

$otvet = curl( 'https://api.vk.com/method/photos.getOwnerPhotoUploadServer?owner_id=xxxxxxx&v=5.45&access_token=' . $token );

$uploadJson = json_decode( $otvet, true )[ 'response' ];
$info_server_photo = curl( $uploadJson[ 'upload_url' ] );



$ch = curl_init(); 
curl_setopt( $ch, CURLOPT_URL, $uploadJson[ 'upload_url' ] ); 
curl_setopt( $ch, CURLOPT_POST, 1 ); 
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS,  array( 'file1' => '@' . dirname( __FILE__ ) . '\\' . $img ) ); 
$otvet_photo = curl_exec( $ch ); 
curl_close( $ch );

$info_server_photo = json_decode( $otvet_photo, true );
$savePhoto = curl( 'https://api.vk.com/method/photos.saveWallPhoto?access_token=' . $token . '&server=' . $info_server_photo[ 'server' ] . '&photo=' . $info_server_photo[ 'photo' ] . '&hash=' . $info_server_photo[ 'hash' ] );
print_r( json_decode( $savePhoto, true ) );

function curl( $url ){
    $ch = curl_init( $url );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    $response = curl_exec( $ch );
    curl_close( $ch );
    return $response;    
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Kos, 2016-02-28
@djalexsey

Error 129 means that you have uploaded an invalid image format.
Error 100 means that one of the required parameters was not passed or is incorrect.

$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$img = "1.png";

$otvet = curl( 'https://api.vk.com/method/photos.getOwnerPhotoUploadServer?owner_id=xxxxxxx&v=5.45&access_token=' . $token );

$uploadJson = json_decode( $otvet, true )[ 'response' ];
$info_server_photo = curl( $uploadJson[ 'upload_url' ] );



$ch = curl_init(); 
curl_setopt( $ch, CURLOPT_URL, $uploadJson[ 'upload_url' ] ); 
curl_setopt( $ch, CURLOPT_POST, 1 ); 
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS,  array( 'file' => dirname( __FILE__ ) . '\\' . $img ) ); 
$otvet_photo = curl_exec( $ch ); 
curl_close( $ch );

$info_server_photo = json_decode( $otvet_photo, true );
$savePhoto = curl( 'https://api.vk.com/method/photos.saveWallPhoto?access_token=' . $token . '&server=' . $info_server_photo[ 'server' ] . '&photo=' . $info_server_photo[ 'photo' ] . '&hash=' . $info_server_photo[ 'hash' ] );
print_r( json_decode( $savePhoto, true ) );

function curl( $url ){
    $ch = curl_init( $url );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    $response = curl_exec( $ch );
    curl_close( $ch );
    return $response;    
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question