gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:32:17 25 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/44078440/

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