Streetview Publish API with PHP - 找不到上传参考 [英] Streetview Publish API with PHP - The upload reference cannot be found

查看:63
本文介绍了Streetview Publish API with PHP - 找不到上传参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我已经完成了第一部分的工作,可以将上传 URL 检索到变量 $upload_url.

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

这是我第 2 步的代码

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 没有返回任何内容,$response 返回 true,所以我假设文件已正确上传.

curl_error is not returning anything, and $response returns true, so I am assuming the file was properly uploaded.

对于第 3 步,我正在使用

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

如果我 var_dump($result) 我收到 404 提示上传的文件不在 uploadUrl

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.

推荐答案

我在第 2 步使用 curl lib 在 PHP 中遇到了类似的问题.用服务器端调用替换 curl-php 已为我解决,但您需要知道完整的文件路径,即:

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

这是我的第 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 系统.希望这会有所帮助.

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

这篇关于Streetview Publish API with PHP - 找不到上传参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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