Street View Publish API PHP - 上传元数据后找不到上传参考
Posted
技术标签:
【中文标题】Street View Publish API PHP - 上传元数据后找不到上传参考【英文标题】:Street View Publish API PHP - The upload reference cannot be found after upload metadata 【发布时间】:2017-10-17 03:34:12 【问题描述】:我正在使用 php 发布全景图像。我在Google Document 中执行了 3 个步骤,并在上传元数据后成功接收到 PhotoID,但是当我将这些 photoID 用于其他请求时,它返回“找不到上传参考。请确保您已将文件上传到上传参考URL。如果此错误仍然存在,请请求新的上传 URL,然后重试”。
这是我的代码:
获取上传网址
$cur_upload_url = curl_init();
curl_setopt_array($cur_upload_url, array(
CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo:startUpload?key=$api_key",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "" ,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer $access_token",
"content-type: application/json",
"Content-Length: 0"
),
));
$response = curl_exec($cur_upload_url);
echo $response;
$re = '/https?:\/\/[^"]*/';
$str = $response;
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
$upload_url = $_SESSION['UploadRef'] = $matches[0][0];
回应:
"uploadUrl":"https://streetviewpublish.googleapis.com/media/user/104039888676357869012/photo/2857577503984652262"
上传照片到上传网址:
$cmd = exec("curl --request POST \
--url '$upload_url' \
--upload-file '$imagePath' \
--header 'Authorization: Bearer $access_token'"
, $outputAndErrors, $return_value);
什么都不返回。
上传元数据
$curl_meta = curl_init();
curl_setopt_array($curl_meta, array(
CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo?key=$api_key",
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => '
"uploadReference":
"uploadUrl": "'.$upload_url.'"
,
"pose":
"heading": 95.0,
"latLngPair":
"latitude": '.$latVal.',
"longitude": '.$langVal.'
,
"captureTime":
"seconds": '.$time_stamp.'
,
',
CURLOPT_HTTPHEADER => array(
"authorization: Bearer $access_token",
"content-type: application/json"
),
));
$response_meta = curl_exec($curl_meta);
回应
"photoId":
"id":"CAoSLEFGMVFpcE4wTDEycFl6S2xVOWtUWmlRVHZCSm90bHp6QUpRWVZ5QlNoWnF4"
当我尝试更新连接或运行 photo.create API 时:
$curl_meta = curl_init();
curl_setopt_array($curl_meta, array(
CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo?key=$api_key",
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => '
"photoId":
"id": "'.$photoID.'"
,
"uploadReference":
"uploadUrl": "'.$upload_url.'"
,
"captureTime": "'.(new DateTime())->format('Y-m-d\TH:i:s\Z').'",
"connections": [],
"places": [],
"pose":
"heading": 0
',
CURLOPT_HTTPHEADER => array(
"authorization: Bearer $access_token",
"content-type: application/json"
),
));
$response_meta = curl_exec($curl_meta);
它响应
"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"
使用返回的 photoID 获取照片
exec('curl --request GET \
--url "'. addslashes('https://streetviewpublish.googleapis.com/v1/photo/'.$photoID.'?key='.$api_key) .'" \
--header "Authorization: Bearer '. addslashes($access_token) .'" ',
$outputAndErrors, $return_value);
回应
"error":
"code":404,
"message":"Image not found for id: CAoSLEFGMVFpcE9faE52aG95TTYtaENjd1NRX3BCU2l4czcwVnVXQS1jd3dxMGxO",
"status":"NOT_FOUND"
我很困惑,需要找到解决方案。
非常感谢!
【问题讨论】:
【参考方案1】:我还使用Try this API 部分尝试了您的请求,但遇到了同样的错误。正如我所观察到的,photo.create
用于发布上传的照片,就像3. Upload the metadata of the photo 一样。当我重试并删除 photoId
参数时,
"uploadReference":
"uploadUrl": "https://streetviewpublish.googleapis.com/media/user/1234567890/photo/1234567890"
,
"connections": [],
"places": [],
"pose": ,
我成功获得了 200 和 photoID(您将收到与 3. Upload the metadata of the photo 相同的输出)。
关于“使用返回的photoID获取照片”,我认为没有必要在您的请求中输入addslashes
。
$ curl --request GET \
--url 'https://streetviewpublish.googleapis.com/v1/photo/PHOTO_ID?key=YOUR_API_KEY' \
--header 'authorization: Bearer YOUR_ACCESS_TOKEN'
【讨论】:
以上是关于Street View Publish API PHP - 上传元数据后找不到上传参考的主要内容,如果未能解决你的问题,请参考以下文章
将 Street View Text 数据集的 GroundTruth 标注在图像上
ArcGIS API for JavaScript3.x 学习笔记[4] 加载底图Open Street Map开放街道地图
使用 facebook API 的 stream.publish 方法时出现权限错误