我通过PHP遇到一些Streetview Publish API问题,尝试复制文档中“上传照片”下列出的程序
https://developers.google.com/streetview/publish/first-app
我的第一部分工作正常,可以将上传网址检索到变量$ 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 :(得分: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.\" }"
}
]
}
}
答案 1 :(得分:0)
我在PHP中使用curl lib遇到了类似的问题。 用服务器端调用替换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系统..希望这会有所帮助。