[英]How do I use the Google drive API key to access drive content from android application?
我無法訪問Google雲端硬盤。 我在Google API控制台中創建了API KEY,並啟用了Google Drive API和SDK。 如何在代碼中設置該API密鑰?
驅動器構建器沒有setJsonHttpRequestInitializer
方法。 我在哪里可以設定KEY?
private Drive getDriveService(String token) {
HttpTransport ht = AndroidHttp.newCompatibleTransport();
JacksonFactory jsonFactory = new JacksonFactory();
Credential credentials = new GoogleCredential().setAccessToken(token);
Drive.Builder b = new Drive.Builder(ht, jsonFactory, credentials);
b.setHttpRequestInitializer(credentials);
return b.build();
}
獲得:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Access Not Configured",
"reason" : "accessNotConfigured"
} ],
"message" : "Access Not Configured"
}
您需要在API控制台中激活兩件事:-驅動器API-驅動器SDK
許多人只能激活一個。
此外,不要忘記在發布最終應用程序之前添加您的真實證書SHA1。
有類似的答案: Google Drive SDK異常
在Android中,按照pommedeterresautee的指定,我們需要執行Drive API和Drive SDK的激活,然后激活API Key。
這必須在Android清單中的application標簽內進行設置,並且與其他application組件標簽相同,如下所示:
<application...>
<activity ...>
<meta-data
android:name="com.google.android.apps.drive.APP_ID"
android:value="id=YOUR_API_KEY" />
</application>
執行此操作時,您將能夠訪問api,而不會出現403“未配置訪問權限”問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.