Answer the question
In order to leave comments, you need to log in
What is the reason for the AppWidgets image upload error in VK?
Everything works, but at the end I get [api] request appWidgets.saveGroupImage failed (code=129 msg='Invalid photo: file not found, from upl_855432?act=app_widget_image')
and I can't figure out how to solve the problem
Picture in 24x24 resolution
<?php
$upl_url = vk_api_call('appWidgets.getGroupImageUploadServer', array(
'image_type' => "24x24"));
$link = $upl_url['upload_url'];
$lala = dirname(__FILE__)."/online.jpg";
$cfile = curl_file_create($lala,'image/jpeg','online.jpg');
$curl=curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $link,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array("photo" => $cfile)
));
$response = curl_exec($curl);
$res = json_decode($response, true);
$mem =$res['hash'];
$memimage =$res['image'];
print_r($res);
$finish = vk_api_call('appWidgets.saveGroupImage', array(
'hash' => $mem, 'image' => $memimage ));
print_r($finish);
function vk_api_call($method, $params = array())
{
return vk_call($method, "ТОКЕН", $params);
}
function vk_call($method, $token, $params = array())
{
if(!isset($params['lang'])) {
$params['lang'] = "ru";
}
if(!isset($params['v'])) {
$params['v'] = "5.80";
}
if(!isset($params['access_token'])) {
$params['access_token'] = $token;
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.vk.com/method/".$method);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
$response = curl_exec($curl);
curl_close($curl);
if($response === false) {
return false;
}
$data = json_decode($response, true);
if($data === false) {
return false;
}
if(!isset($data['response']))
{
logs("[api] request ".$method." failed (code=".$data['error']['error_code']." msg='".$data['error']['error_msg']."')");
return false;
}
logs("[api] request ".$method." successful");
return $data['response'];
}
function logs($line)
{
print(sprintf("[%s] %s\n", date(DATE_ATOM, time()), $line));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question