1

I'm using PHP to publish panoramic image images. I'm following 3 steps in Google Document and successfully received PhotoID after uploaded metadata, but when I using these photoID for other request, it return "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".

Here is my code:

Get Upload URL

$cur_upload_url = curl_init();
  curl_setopt_array($cur_upload_url, array(
   CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo:startUpload?key=$api_key",
   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);
  echo $response;
  $re = '/https?:\/\/[^"]*/';
  $str = $response;
  preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
  $upload_url = $_SESSION['UploadRef'] = $matches[0][0];

Response:

{  
   "uploadUrl":"https://streetviewpublish.googleapis.com/media/user/104039888676357869012/photo/2857577503984652262"
}

Upload photo to Upload URL:

$cmd = exec("curl --request POST \
        --url '$upload_url' \
        --upload-file '$imagePath' \
        --header 'Authorization: Bearer $access_token'"
    , $outputAndErrors, $return_value);

It's return nothing.

Upload the metadata

$curl_meta = curl_init();
  curl_setopt_array($curl_meta, array(
    CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo?key=$api_key",
    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

{  
   "photoId":{  
      "id":"CAoSLEFGMVFpcE4wTDEycFl6S2xVOWtUWmlRVHZCSm90bHp6QUpRWVZ5QlNoWnF4"
   }
}

And when I'm trying to update the connection or run photo.create API:

$curl_meta = curl_init();
  curl_setopt_array($curl_meta, array(
    CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo?key=$api_key",
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => '{
  "photoId": {
    "id": "'.$photoID.'"
  },
  "uploadReference": {
    "uploadUrl": "'.$upload_url.'"
  },
  "captureTime": "'.(new DateTime())->format('Y-m-d\TH:i:s\Z').'",
  "connections": [],
  "places": [],
  "pose": {
    "heading": 0
  }
}',
    CURLOPT_HTTPHEADER => array(
       "authorization: Bearer $access_token",
       "content-type: application/json"
    ),
  ));
      $response_meta = curl_exec($curl_meta);

It response

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

Get the photo with the returned photoID

exec('curl --request GET \
--url "'. addslashes('https://streetviewpublish.googleapis.com/v1/photo/'.$photoID.'?key='.$api_key) .'" \
--header "Authorization: Bearer '. addslashes($access_token) .'" ',
$outputAndErrors, $return_value);

Response

"error":{  
      "code":404,
      "message":"Image not found for id: CAoSLEFGMVFpcE9faE52aG95TTYtaENjd1NRX3BCU2l4czcwVnVXQS1jd3dxMGxO",
      "status":"NOT_FOUND"
   }

I am so stuck and need to find a solution.

Thanks a lot!

Community
  • 1
  • 1

1 Answers1

1

I also tried your request using the Try this API section and encountered the same error. As I observed, photo.create is used to publish the uploaded Photo just like the 3. Upload the metadata of the photo. When I retried this and removed the photoId parameter,

{
 "uploadReference": {
   "uploadUrl": "https://streetviewpublish.googleapis.com/media/user/1234567890/photo/1234567890"
 },
 "connections": [],
 "places": [],
 "pose": {},
}

I successfully got 200 and the photoID (same output you'll receive with 3. Upload the metadata of the photo).

enter image description here

Regarding "Get the photo with the returned photoID", I don't think it is necessary to put addslashes in your request.

$ curl --request GET \
--url 'https://streetviewpublish.googleapis.com/v1/photo/PHOTO_ID?key=YOUR_API_KEY' \
--header 'authorization: Bearer YOUR_ACCESS_TOKEN'
abielita
  • 13,147
  • 2
  • 17
  • 59