2016-11-15 167 views
1

我正在使用谷歌oauth v2 HTTP請求獲取toke工作正常,我得到的令牌,但是當使用令牌訪問電子表格時,我得到一個403錯誤。Google Sheet API curl獲取請求

這是我正在使用的請求代碼。

$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":"[email protected]", 
    "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.' 
} 

我在做什麼錯?

+2

看起來您正在驗證的用戶無權訪問該工作表。還要確保您使用了正確的範圍來驗證用戶。 – DaImTo

+0

我已在API控制檯中將其打開。我還有其他地方需要爲該用戶啓用工作表嗎? – sacarr

回答

2

問題解決了

我試圖訪問與我的客戶ID(電子郵件地址) 該板在谷歌上右擊驅動器和一個電子郵件地址分享所需共享的片材。

發佈此問題的任何人有同樣的問題。