获取我通过这种方式解决的上传 URL
$cur_upload_url = curl_init();
curl_setopt_array($cur_upload_url, array(
CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo:startUpload?key=XXXXXXXXXXX" ,
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];
echo $upload_url;
将照片字节上传到上传 URL
$cmd = exec('curl --request POST \--url "'. addslashes($upload_url) .'" \--upload-file "'.$imagePath.'" \--header "Authorization: Bearer '. addslashes($access_token) .'" ');
然后上传照片的元数据
$curl_meta = curl_init();
curl_setopt_array($curl_meta, array(
CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo?key=XXXXXXXXXXXXXXXX",
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);
$response_json = json_decode($response_meta, true);
// $photoID = $response_json['photoId']['id'];
// echo $photoID;
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);
从这里您将获得带照片的身份证件。
获取 Photo iD 后发布成功。