問題描述
我正在嘗試編寫一個 AppEngine 應用程序,該應用程序將 Google 文檔寫入 Google Drive,放入一組特定的文件夾并設置訪問權限.我可以使用舊的 DocsList API,但由于它剛剛被棄用,我決定更新我的代碼(無論如何我還有一些額外的功能要添加).
I'm trying to write an AppEngine app that writes a Google Document to Google Drive, puts in a specific set of folders and sets access rights. I have this working with the old DocsList API but since that just got deprecated I decided to update my code (and I had some additional functions to add anyway).
我面臨的問題是:當我使用服務帳戶并嘗試模擬特定用戶時,即使我沒有用完任何配額,我也會收到帶有 usageLimits 的 403.
Problem I'm facing is this: When I use a service account and try to impersonate a specific user I get a 403 with usageLimits even though I have not used up any of my quota.
這是我正在使用的代碼:
Here is the code I'm using:
GoogleCredential credentials = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("xxxxxxxxxxgserviceaccount.com")
.setServiceAccountScopes(DriveScopes.DRIVE)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File("xxxx-privatekey.p12"))
.setServiceAccountUser("user@xxxxxx.org").build();
我會使用這些憑據來啟動我的 Drive 對象:
I than use these credentials to initiate my Drive object:
Drive d = Drive.builder(httpTransport, jsonFactory)
.setHttpRequestInitializer(credentials)
.setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
@Override
public void initialize(JsonHttpRequest request) {
DriveRequest driveRequest = (DriveRequest) request;
driveRequest.setPrettyPrint(true);
}
}).setApplicationName("MYAPPNAME").build();
順便說一句:我嘗試過使用 new Drive(....) ,但無論我嘗試什么都行不通.不斷拋出找不到內部方法的錯誤!
BTW: I've tried using new Drive(....) but that just won't work, no matter what I try. Keeps throwing errors that internal methods are not found!
回到這個問題:當我使用 'd' 調用類似 .files().get("SOMEFILEID").execute() 的東西時,我得到一個 403
Back to this issue: When I than use 'd' to call something like .files().get("SOMEFILEID").execute() I get a 403
{ "code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Daily Limit Exceeded. Please sign up",
"reason" : "dailyLimitExceededUnreg",
"extendedHelp" : "https://code.google.com/apis/console"
} ],
"message" : "Daily Limit Exceeded. Please sign up"
}
我不明白為什么這不起作用.我在網上看了一整天,但找不到合適的答案.非常感謝一些幫助.
I can't figure out why this doesn't work. I've look online all day but can't find a suitable answer. Some help is very much appreciated.
推薦答案
當 API 調用缺少 Authorization http 標頭時,我通常會得到 403.跟蹤 http 并查看標頭.配額"消息的基本原理是,如果沒有 Auth 標頭,您就是匿名的,匿名使用的配額為零.
I usually get a 403 when the API call was missing the Authorization http header. Trace the http and look at the headers. The rationale for the "quota" message is that without an Auth header, you are anonymous, and the quota for anonymous use is zero.
您還可以檢查您的應用是否已注冊兩個 Drive API,因為我聽說這可能會導致同樣的問題.
You might also check that your app is registered for both of the Drive APIs, as I've heard that that can cause the same problem.
關于內部方法問題,聽起來您使用的是不兼容的庫版本.最適合我的方法是刪除我下載的所有庫以及示例代碼,然后使用 Google Eclipse 插件Google/Add Google APIs..."下載所有最新版本.
On the internal method issue, that sounds like you're using incompatible library versions. What worked best for me was to delete all of the libraries I had downloaded with the sample code, then use the Google Eclipse plugin to "Google/Add Google APIs..." to download all of the latest versions.
這篇關于Google Drive 服務帳號返回 403 usageLimits的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!