0

我在通过 PHP 使用 Streetview Publish API 时遇到一些问题,试图复制文档中“上传照片”下列出的过程

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" 
  } 
} " 

欢迎任何建议,我的直觉是问题出在第二步而不是第三步,但我对所有建议持开放态度。提前致谢。

4

2 回答 2

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来检查图像。

于 2017-08-15T09:17:15.407 回答
0

我在第 2 步使用 curl lib 在 PHP 中遇到了类似的问题。用为我解决的服务器端调用替换 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 系统。希望这会有所帮助。

于 2017-09-14T15:52:04.820 回答