0

我使用PHP发布全景图像。我在Google Document中执行了3个步骤,并且在上传元数据后成功接收了PhotoID,但是当我使用这些PhotoID作为其他请求时,它将返回“无法找到上传参考。请确保您已上传文件到上传参考URL。如果此错误仍然存​​在,请申请一个新的上传网址并重试“。Street View Publish API PHP - 上传元数据后无法找到上传参考

这里是我的代码:

获取上传的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]; 

响应:

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

上传照片上传网址:

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

它没有任何回报。

上传元数据

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

响应

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

当我试图更新连接或运行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); 

它回应

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

获取照片与返回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); 

响应

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

我如此坚持,需要找到一个解决方案。

非常感谢!

回答

0

我也尝试过使用Try this API部分的请求,并且遇到了同样的错误。正如我所观察到的,photo.create用于发布上传的照片,就像3. Upload the metadata of the photo一样。当我试这一点,并删除photoId参数,

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

我顺利地拿到了200和PHOTOID(相同的输出,你会收到3. Upload the metadata of the photo)。

enter image description here

关于“获取与返回PHOTOID照片”,我不认为有必要把addslashes在您的要求。

$ curl --request GET \ 
--url 'https://streetviewpublish.googleapis.com/v1/photo/PHOTO_ID?key=YOUR_API_KEY' \ 
--header 'authorization: Bearer YOUR_ACCESS_TOKEN'