gpt4 book ai didi

android - 是否可以在后台连接到 Drive API?

转载 作者:行者123 更新时间:2023-11-29 01:23:25 25 4
gpt4 key购买 nike

我想在后台保存用户数据,但我不知道如何在没有用户交互的情况下连接到 Drive API。

根据我第一次连接后的理解

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstance);

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}

我想获得一个刷新 token ,稍后我将使用它来获取访问 token ,我将使用它连接到 API 并保存用户数据。 Drive API for Android 看起来不可行

另外,如果有人指出我如何以正确的方式做到这一点,我将不胜感激!

最佳答案

要实现从后台服务将文件保存到云端硬盘,您需要启动一个 Activity ,您将在其中处理权限 Activity 的 Activity 结果。

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (resultCode == Activity.RESULT_OK) {
// permission is given
finish();
} else {
or show error
}
}

获得refresh token为了允许长期访问,您的应用程序请求授权以访问由范围标识的资源。您需要在身份验证请求中添加 prompt=consent 参数。当包含 prompt=consent 时,每次登录您的应用程序时都会显示同意屏幕。刷新 token 仅在第一次授予应用程序权限时返回。

基于此thread :

The refresh_token is only provided on the first authorization from the user. Subsequent authorizations, such as the kind you make while testing an OAuth2 integration, will not return the refresh_token again.

然后使用refresh token生成access token,可以引用这个question .

关于android - 是否可以在后台连接到 Drive API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35443783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com