Streetview Publish API with PHP - The upload reference cannot be found

巧了我就是萌 提交于 2019-12-12 04:54:23

问题


I'm having some issues with the Streetview Publish API through PHP, attempting to replicate the procedure listed under "Uploading a photo" in the documentation

https://developers.google.com/streetview/publish/first-app

I've got the first part working and can retrieve the upload URL to a variable $upload_url.

This is my code for step 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 is not returning anything, and $response returns true, so I am assuming the file was properly uploaded.

For step 3, I'm using

$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);

If I var_dump($result) I get a 404 suggesting that the uploaded file isn't at the 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" 
  } 
} " 

Any advice would be welcome, my instinct is that the issue is with the second step rather than the third, but I'm open to all suggestions. Thanks in advance.


回答1:


I also encountered this error when I tried uploading panorama pictures.

"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.\" }"
      }
    ]
  }
}

It seems that you are not uploading a correct 360 photo. Make sure that the 360 picture you are uploading has metadata. You may download this ExifTool to check the image.




回答2:


I've got a similar problem in PHP with curl lib at step 2. Replacing curl-php with a server side call resolved for me but you need to know full file path i.e.:

$_SERVER['DOCUMENT_ROOT'].$webdir.$filename

here is my step 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']) .'" ');

The server is some sort of cloud hosted Linux system.. hope this helps.



来源:https://stackoverflow.com/questions/45674293/streetview-publish-api-with-php-the-upload-reference-cannot-be-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!