【问题标题】:Google Sheet API php curl get requestGoogle Sheet API php curl 获取请求
【发布时间】:2017-03-29 09:27:00
【问题描述】:

我正在使用 google oauth v2 HTTP 请求来获取工作正常的访问令牌,我正在获取令牌,但是在使用令牌访问电子表格时出现 403 错误。

这是我正在使用的请求代码。

$get = 'https://sheets.googleapis.com/v4/spreadsheets/1bHKgQLgqB4PfjRUVPkYk5_L7aQOtZGOkhJbr_RFxQQY?access_token='.$access_token;

$ch = curl_init();  

curl_setopt($ch,CURLOPT_URL,$get);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false); 
$output = curl_exec($ch);
curl_close($ch);

var_dump($output);

这是带有标题的返回

HTTP/1.1 403 Forbidden
Vary: X-Origin
Vary: Referer
Content-Type: application/json; charset=UTF-8
Date: Tue, 15 Nov 2016 13:13:09 GMT
Server: ESF
Cache-Control: private
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alt-Svc: quic=":443"; ma=2592000; v="36,35,34"
Accept-Ranges: none
Vary: Origin,Accept-Encoding
Transfer-Encoding: chunked

{
  "error": {
  "code": 403,
  "message": "The caller does not have permission",
  "status": "PERMISSION_DENIED"
  }
}

我已经厌倦了公开工作表,但这对错误没有影响。 API 控制台上也未显示该错误。

这些是我正在使用的范围:

{
   "iss":"dev-537@mortgagetest-149109.iam.gserviceaccount.com",
   "scope":"https://www.googleapis.com/auth/drive    
    https://www.googleapis.com/auth/drive.readonly 
    https://www.googleapis.com/auth/spreadsheets 
    https://www.googleapis.com/auth/spreadsheets.readonly",
   "aud":"https://accounts.google.com/o/oauth2/token",
   "exp":'.($time+3600).',
   "iat":'.$time.'
}

我做错了什么?

【问题讨论】:

  • 看起来您正在验证的用户无权访问该工作表。还要确保您使用了正确的范围来对用户进行身份验证。
  • 我已经在 API 控制台中开启了它。还有其他地方我必须为该用户启用工作表吗?

标签: php curl oauth google-api google-sheets-api


【解决方案1】:

解决了问题

我尝试访问的工作表需要与我的客户 ID(电子邮件地址)共享 右键单击谷歌驱动器中的工作表并与电子邮件地址共享。

为有同样问题的任何人发布此信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-26
    • 2017-11-25
    相关资源
    最近更新 更多