php curl — API публикации Streetview с ссылкой для загрузки не найден

У меня проблемы с API Streetview Publish через PHP, я пытаюсь повторить процедуру, описанную в разделе «Загрузка фотографии» в документации

https://developers.google.com/streetview/publish/first-app

У меня работает первая часть, и я могу получить URL для загрузки в переменную $ upload_url.

Это мой код для шага 2

    $another = array(
'upload-file' => curl_file_create($imagepath)
);
$header = array (
"Authorization: Bearer $accesstoken",
"Content-Type: multipart/form-data");
$options = array(
CURLOPT_URL => $upload_url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $another,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);echo(curl_error($ch));
curl_close($ch);

var_dump($response);

curl_error ничего не возвращает, и $response возвращает true, поэтому я предполагаю, что файл был правильно загружен.

Для шага 3 я использую

$data['uploadReference']['uploadUrl']=$upload_url;
$data['pose']['latLngPair']['latitude']=$latitude;
$data['pose']['latLngPair']['longitude']=$longitude;

$data['captureTime']['seconds']=$timestamp;$data_string = json_encode($data);

print_r($data);
$ch = curl_init('https://streetviewpublish.googleapis.com/v1/photo?key='.$apikey);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'authorization: Bearer '.$accesstoken,
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);

curl_close ($ch);

Если я var_dump($result) Я получаю 404, предполагая, что загруженный файл не на uploadUrl

Array ( [uploadReference] => Array ( [uploadUrl] => https://streetviewpublish.googleapis.com/media/user/XXXX/photo/YYYY ) [pose] => Array ( [latLngPair] => Array ( [latitude] => 53.59398125 [longitude] => -1.95349941 ) ) [captureTime] => Array ( [seconds] => 1502560132 ) ) string(255)
"{
"error": {
"code": 404,
"message": "The upload reference cannot be found. Please make sure you have uploaded a file to the upload reference URL. If this error persists, request a new upload URL and try again.",
"status": "NOT_FOUND"}
} "

Любой совет будет приветствоваться, мой инстинкт в том, что проблема со вторым шагом, а не с третьим, но я открыт для всех предложений. Заранее спасибо.

0

Решение

Я также столкнулся с этой ошибкой, когда пытался загрузить панорамные изображения.

"error": {
"code": 404,
"message": "The upload reference cannot be found. Please make sure you have uploaded a file to the upload reference URL. If this error persists, request a new upload URL and try again.",
"status": "NOT_FOUND",
"details": [
{
"@type": "type.googleapis.com/google.rpc.DebugInfo",
"detail": "[ORIGINAL ERROR] generic::not_found: com.google.geo.ugc.streetview.publish.boq.service.util.ApiException: The upload reference cannot be found. Please make sure you have uploaded a file to the upload reference URL. If this error persists, request a new upload URL and try again. Code: NOT_FOUND [google.rpc.error_details_ext] { message: \"The upload reference cannot be found. Please make sure you have uploaded a file to the upload reference URL. If this error persists, request a new upload URL and try again.\" }"}
]
}
}

Похоже, вы не загружаете правильную фотографию 360. Убедитесь, что загружаемое изображение 360 имеет метаданные. Вы можете скачать это ExifTool проверить изображение.

0

Другие решения

У меня похожая проблема в PHP с curl lib на шаге 2.
Замена curl-php на вызов на стороне сервера решена для меня, но вам нужно знать полный путь к файлу, т.е.

$_SERVER['DOCUMENT_ROOT'].$webdir.$filename

вот мой шаг 2:

$result = exec('curl --request POST \--url "'. addslashes($upload_url) .'" \--upload-file "'.$file_name_with_full_path.'" \--header "Authorization: Bearer '. addslashes($_GOOGLE_API['access_token']) .'" ');

Сервер — это своего рода облачная система Linux … надеюсь, это поможет.

0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector