【问题标题】:com.google.api.client.extensions.android.http.androidhttp is deprecatedcom.google.api.client.extensions.android.http.androidhttp 已弃用
【发布时间】:2020-04-27 10:37:14
【问题描述】:

您好,我尝试在 android 应用程序上与 google drive api 进行通信,但我看到这已被 google 弃用,我该如何解决我的代码?

    void fun(GoogleSignInAccount signInAccount){
    Log.d("jjj","fun called");
    GoogleAccountCredential credential =
            GoogleAccountCredential.usingOAuth2(
                    this, Collections.singleton(DriveScopes.DRIVE_FILE));
    credential.setSelectedAccount(signInAccount.getAccount());
    Drive googleDriveService =
            new Drive.Builder(
                    AndroidHttp.newCompatibleTransport(),
                    new GsonFactory(),
                    credential)
                    .setApplicationName("Drive API Migration")
                    .build();
    editor.putBoolean("SyncOn",true).commit();
    mDriveServiceHelper = new DriveServiceHelper(googleDriveService);

图片有问题: deprecated code picture - line problem

【问题讨论】:

    标签: java android google-drive-api


    【解决方案1】:

    不使用AndroidHttp,直接使用NetHttpTransport,或者切换到支持更好的Cronet。

    Drive googleDriveService = new Drive.Builder(
            new NetHttpTransport(),
            new GsonFactory(),
            credential)
        .setApplicationName("Drive API Migration")
        .build();
    

    参考:https://github.com/googleapis/google-http-java-client/blob/master/google-http-client-android/src/main/java/com/google/api/client/extensions/android/http/AndroidHttp.java#L35

    【讨论】:

      猜你喜欢
      • 2019-07-03
      • 2014-02-12
      • 1970-01-01
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      相关资源
      最近更新 更多