我正在創建一個應用程序,以在Android上使用Google Drive。該方法setJsonHttpRequestInitializer是未定義的類型Drive.Builder Android
我在網上搜索了幾個例子,但它們都是一樣的。我收到以下錯誤:
Object Drive.Builder does not have method setJsonHttpRequestInitializer.
我已經使用Google驅動器API V1和V2進行了測試,但運氣不佳。
問題在哪裏?
來源:
private Drive getDriveService(String accountName) {
HttpTransport ht = AndroidHttp.newCompatibleTransport();
JacksonFactory jf = new JacksonFactory();
Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accountName);
Drive.Builder b = new Drive.Builder(ht, jf, null);
b.setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
@Override
public void initialize(JsonHttpRequest request) throws IOException {
DriveRequest driveRequest = (DriveRequest) request;
driveRequest.setPrettyPrint(true);
driveRequest.setOauthToken(accountName);
driveRequest.setKey(API_KEY);
}
});
return b.build();
}
發現,如果使用Google API-Java的客戶機-1.12.0-β
下載和進口谷歌-API的Java的客戶機 - 1.11 setJsonHttpRequestInitializer方法是未定義.0-beta
但是現在得到: 對已安裝的應用程序使用客戶端ID:客戶端ID。
com.google.api.client.http.HttpResponseException: 403 Forbidden
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured"
}
],
"code": 403,
"message": "Access Not Configured"
}
}
使用簡單API訪問:API密鑰
Exceptioncom.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Invalid Credentials",
"reason" : "authError"
} ],
"message" : "Invalid Credentials"
}
這裏是項目來源:
http://www.sendspace.com/file/an6xxy
什麼是錯的,或許真的有證書指紋(SHA1)?
嘗試從谷歌的calendar-android-sample。
看起來像我在谷歌API控制檯註冊應用程序的問題。
在哪裏把我得到的樣品客戶端ID?
在Android的調試模式下運行示例後,得到「訪問未配置」。
是的,這有幫助。但現在得到該訪問未配置。我在Google Drive的Google api控制檯中創建了API KEY,並將其寫入Manifets中,但沒有成功。 Exceptioncom.google.api.client.googleapis.json。GoogleJsonResponseException:403禁止 { 「代碼」:403, 「錯誤」:[{ 「域」: 「usageLimits」, 「消息」: 「訪問未配置」, 「原因」: 「accessNotConfigured」 } ], 「message」:「未配置訪問」 } – user1826780
Drive API不使用API密鑰進行授權,而是需要https://developers.google.com/android/google中所述的授權令牌-play-services/authentication –
添加了更多信息,有人可以幫忙嗎? – user1826780