Google 驱动器 Android API 身份验证问题

Google Drive Android API Authentication Problems

我正在开发一个应用程序,它在 Google 的私有应用程序数据文件夹中创建/更新单个文本文件。这是通过 REST v3 Drive API 完成的。 几天前它工作得很好,现在不行了。据我所知,唯一改变的是我将它上传到 Google Play。我是 我的应用程序连接到应用程序时遇到问题,因为 service 变量返回 null。我的想法是,也许我需要一个刷新令牌或其他东西,但我无法找到有关如何使用 v3 API 执行此操作的任何信息。 我将非常感谢对此的一些帮助。

这是我到目前为止尝试过的方法:
1. 创建一个新的密钥库并使用新的 sha1 指纹
重新下载 google-services.json 文件 2. 禁用并重新启用驱动器 API
3. 我在 'release' 变体上开发我的项目,可能很糟糕,但它在
之前工作 4. 用头撞墙

这是源代码:

// Gather credentials
credential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(SCOPES)).setBackOff(new ExponentialBackOff());
SharedPreferences settings = getSharedPreferences("Roblu", Context.MODE_PRIVATE);
String accountName = settings.getString("accountName", "");
credential.setSelectedAccountName(accountName);

// Start Google services
HttpTransport transport = AndroidHttp.newCompatibleTransport();

JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
// This is returning null
service = new Drive.Builder(transport, jsonFactory, credential).setApplicationName("Roblu").build();
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();

编辑
此行为 Drive 对象返回 null。想法?

service = new com.google.api.services.drive.Drive.Builder(transport, jsonFactory, credential).setApplicationName("Roblu").build();

当您发布使用 Google 服务(如 Drive REST API)的应用程序时,您需要为该应用程序的生产版本添加凭据,其中的 SHA1 指纹来自您用于签署 APK 的同一密钥库。

通常在测试期间,您会添加从调试密钥库派生的凭据。此凭据将不能用于应用程序的生产版本。

因此您转到 Google 开发人员控制台 (https://console.developers.google.com/apis/credentials) 并添加一个新凭据。