问题描述
我正在尝试构建一个Android应用程序,该应用程序在Google云端硬盘中创建了一个电子表格,然后向其中添加了一些数据.我可以使用Google Drive Android API成功创建电子表格,其中涉及创建GoogleApiClient
和使用实现GoogleApiClient.ConnectionCallbacks
的类.
I am trying to build an Android application that created a spreadsheet in Google Drive and then adds some data to it. I can successfuly create the spreadsheet using the Google Drive Android API which involves creating a GoogleApiClient
and using a class that implements GoogleApiClient.ConnectionCallbacks
.
启动应用程序时,我会创建一个新的GoogleApiClient
,并提示您选择一个帐户.在onConnected
回调中,我可以将GoogleApiClient
传递给Drive.DriveApi
以查询和创建文件和文件夹.
When I start the application I make a new GoogleApiClient
and am prompted to select an account. In the onConnected
callback I can new pass my GoogleApiClient
to Drive.DriveApi
to query and create files and folders.
但是,要将数据添加到Google工作表中,我需要使用GoogleSheets API.据我所知,它没有Android API,但确实有gdata API.为了使用它,我需要一个OAuth令牌.
However, to add data to a Google sheet I need to use the GoogleSheets API. This does not have an Android API as far as I can tell but it does have a gdata API. In order to use it however I need an OAuth token.
反正我可以从GoogleApiClient
对象获得OAuth令牌吗?
Is there anyway I can get an OAuth token from the GoogleApiClient
object?
推荐答案
是的,您只能使用
GoogleAccountCredential mCredential;
String[] SCOPES = {"https://www.googleapis.com/auth/userinfo.profile"};
mCredential = GoogleAccountCredential.usingOAuth2(mContext, Arrays.asList(SCOPES))
.setBackOff(new ExponentialBackOff())
.setSelectedAccountName(ACC_NAME);
GoogleAuthUtil.getToken(mContext, mCredential.getSelectedAccountName(),SCOPE)
这篇关于如何从GoogleApiClient获取OAuth令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!