替换为Drive.Builder的getJson HttpRequestInitializer

时间:2013-01-14 15:47:27

标签: android google-drive-api

我正在使用google-api-services-drive-v2-rev39-java-1.12.0-beta(写作时最新)

我发现setJsonHttpRequestInitializer

中不再显示Drive.Builder
    final HttpTransport transport = new NetHttpTransport();
    final JsonFactory jsonFactory = new GsonFactory();
    GoogleCredential credential = new GoogleCredential();
    // authToken is String.
    credential.setAccessToken(authToken);
    // ClientCredentials.KEY is String, generated from https://code.google.com/apis/console/b/0/?api=drive#project:369087808589
    Drive service = new Drive.Builder(transport, jsonFactory, credential)
        .setApplicationName(Utils.getApplicationName())
        .setJsonHttpRequestInitializer(new GoogleKeyInitializer(ClientCredentials.KEY))
        .build();

如果我在不调用setJsonHttpRequestInitializer的情况下执行代码,我将获得

超出未经身份验证的使用的每日限制。继续使用需要注册。

我有什么办法可以将API密钥(ClientCredentials.KEY)传递给Drive.Builder吗?

注意:已经检查The method setJsonHttpRequestInitializer is undefined for the type Drive.Builder Android。没有帮助。

1 个答案:

答案 0 :(得分:1)

检查Google云端硬盘SDK文档中的Android快速入门,了解在Android上构建服务和授权请求的正确方法:

https://developers.google.com/drive/quickstart-android