相关疑难解决方法(0)

如何从GoogleCredential获取访问令牌?

我正在尝试获取访问令牌以使用Google Play Android Developer API,而且我使用Google API Java客户端文档示例了解到这一点:

HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
JsonFactory JSON_FACTORY = new JacksonFactory();

GoogleCredential credential = new GoogleCredential.Builder()
    .setTransport(HTTP_TRANSPORT)
    .setJsonFactory(JSON_FACTORY)
    .setServiceAccountId("...gserviceaccount.com")
    .setServiceAccountScopes("https://www.googleapis.com/auth/androidpublisher")
    .setServiceAccountPrivateKeyFromP12File(keyFile)
    .build();
Run Code Online (Sandbox Code Playgroud)

但是如何从此凭据获取访问令牌?credential.getAccessToken()回报null.我做错了什么,或者错过了一些步骤?

authorization credentials google-api access-token oauth-2.0

18
推荐指数
2
解决办法
2万
查看次数