如何解决Google街景发布API错误代码=> 400消息=>图片上传网址与所需格式不匹配 [状态] => INVALID_ARGUMENT
我需要Google街景发布API的支持。我在上传缝合的全景照片时收到401数组([错误] =>数组([代码] => 400 [消息] =>照片上传网址与所需格式不匹配。[状态] => INVALID_ARGUMENT))。请给我参考
<?PHP
$access_token = $_GET['access_token'];
$cur_upload_url = curl_init();
curl_setopt_array($cur_upload_url,array(
CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo:startUpload?
key=AIzaXXXXPDrlfiF7slFVjuDDGMAdwtOpUWcedew3",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);
$re = '/https?:\/\/[^"]*/';
$str = $response;
preg_match($re,$str,$matches,PREG_OFFSET_CAPTURE,0);
$upload_url = $_SESSION['UploadRef'] = $matches[0][0];
$imagePath = "/IMG_7779_Panorama.jpg";
$file_name_with_full_path = $_SERVER['DOCUMENT_ROOT'].$imagePath;
$cmd = exec('curl --request POST \--url "'. $upload_url .'" \--upload-file
"'.$file_name_with_full_path.'" \--header "Authorization: Bearer '. $access_token .'" ');
$latVal = 22.7355728;
$langVal = 88.46367;
$time_stamp = time();
$curl_Meta = curl_init();
curl_setopt_array($curl_Meta,array(
CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo?
key=AIzaSyDqNXXXXfiF7slFVjuDDGMAdwtOpUWredsc",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","referer : http://mywebsite.com/view_360.PHP",),));
$response_Meta = curl_exec($curl_Meta);
$response_json = json_decode($response_Meta,true);
print_r($response_json);
die;
if(curl_errno($curl_Meta)){
// this would be your first hint that something went wrong
die('Couldn\'t send request: ' . curl_error($curl_Meta));
}else{
//check the HTTP status code of the request.
$resultStatus = curl_getinfo($curl_Meta,CURLINFO_HTTP_CODE);
if($resultStatus != 200){
die('Request Failed: HTTP status code: ' . $resultStatus);
}else{
$photoID = $response_json['photoId']['id'];
//insert google publish information into db table
}
}
curl_close($curl_Meta);
?>
我保持规则流畅-
-
我在Google Developers Console中创建了一个项目,并获取了授权凭据,因此我的应用程序可以提交API请求。
-
然后实施了OAuth 2.0授权。
-
照片需要使用Photo Sphere XMP元数据中描述的元数据才能发布。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。