使用街景视图发布API上传全景图像 [英] Upload pano Image using street View Publish API

查看:156
本文介绍了使用街景视图发布API上传全景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用给定的街道View API进行上传时

 请求上传URL 
$ curl - -request POST \
--url'https://streetviewpublish.googleapis.com/v1/photo:startUpload?key=YOUR_API_KEY'\
--header'Authorization:Bearer YOUR_ACCESS_TOKEN'\
--header'Content-Length:0'

将照片字节上传到上传URL
$ curl --request POST \
--url' UPLOAD_URL'\
--upload-file'PATH_TO_FILE'\
--header'Authorization:Bearer YOUR_ACCESS_TOKEN'

但它没有工作..



它给了我错误的请求没有找到文件。



任何人都可以帮助我解决这个问题。



预先感谢您。

解决方案

获取我解决的上传URL通过这种方式

  $ cur_u pload_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 =>数组(
授权: $ 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;


$ b

将照片字节上传到上传网址

  $ cmd = exec('curl --request POST \  -  url'。addslashes($ upload_url)。'\  -  upload-file''。$ imagePath。'\  -  header Authorization:Bearer'。addslashes($ access_token)。'''); 

然后Uplaod meta照片数据

  $ 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:
{
标题:95.0,
latLngPair:
{
latitude:'。$ latVal。',
longitude:'。$ langVal。'
}
},
captureTime:
{
秒:'。$ time_stamp。'
},
}',

CURLOPT_HTTPHEADER => ;数组(
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)){
//这将是您的第一个提示,出现错误
die('Couldn'''t send请求:'。curl_error($ curl_meta));
} else {
//检查请求的HTTP状态码。
$ resultStatus = curl_getinfo($ curl_meta,CURLINFO_HTTP_CODE);
if($ resultStatus!= 200){
die('Request failed:HTTP status code:'。$ resultStatus);
} else {
$ photoID = $ response_json ['photoId'] ['id'];
//将Google发布信息插入到数据库表中





$ b curl_close($ curl_meta);

从这里您将获得照片ID。



获得Photo iD发布成功后。


When I am making upload using the the given street View API

Request an Upload URL
        $ curl --request POST \
        --url 'https://streetviewpublish.googleapis.com/v1/photo:startUpload?key=YOUR_API_KEY' \
        --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
        --header 'Content-Length: 0'

Upload the photo bytes to the Upload URL
        $ curl --request POST \
        --url 'UPLOAD_URL' \
        --upload-file 'PATH_TO_FILE' \
        --header 'Authorization: Bearer YOUR_ACCESS_TOKEN'

But its not Working..

Its giving me the error No file found in request.

Can anybody please help me regarding this ..

Thank you in Advance.

解决方案

To Get the upload URL I solved By this way

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

Upload the photo bytes to the Upload URL

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

Then Uplaod the meta data of photo

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

From here you will get the photo ID.

After getting the Photo iD publish is successful.

这篇关于使用街景视图发布API上传全景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆