gpt4 book ai didi

使用 Auth.GOOGLE_SIGN_IN_API 时的 java.lang.IllegalStateException : Must not set scopes in GoogleApiClient. Builder

转载 作者:太空宇宙 更新时间:2023-11-04 11:12:43 24 4
gpt4 key购买 nike

我正在使用带有身份验证 api 的驱动器 api。我需要先登录谷歌帐户,然后将文件上传到驱动器。问题是,当我仅使用未经身份验证的驱动器 api 时,显示无法登录。我首先使用登录

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, 4);

登录成功。但是当我尝试使用drive api 时,它会给出错误。下面是代码

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, 4);

有什么解决方案可以让我先登录然后将文件添加到驱动器吗?

最佳答案

试试这个代码:

@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();
}

然后设置连接代码以进行授权:

@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}

我正在关注文档 - Authorizing Android Apps ,本文档还提供了如何处理用户之前未授权该应用程序的情况。

希望这有帮助。

关于使用 Auth.GOOGLE_SIGN_IN_API 时的 java.lang.IllegalStateException : Must not set scopes in GoogleApiClient. Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45815146/

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