android - 无法在 Android 上设置范围 Google 登录

标签 android google-api access-token google-signin

我使用 Google API 登录 Android 应用。

代码在这里:

SignInButton btnLogin = (SignInButton) findViewById(R.id.sign_in_button);

btnLogin.setOnClickListener(this);

Scope[] scopes = new Scope[2];
scopes[0] = new Scope("https://www.googleapis.com/auth/admin.directory.user.readonly");
scopes[1] = new Scope("https://www.googleapis.com/auth/contacts.readonly");

btnLogin.setScopes(scopes);

使用访问 token 登录成功,但访问 token 只有默认范围:

"userinfo.profile" & "userinfo.email" & "auth/plus.me"

你能帮我拿两个瞄准镜吗:

"/auth/admin.directory.user.readonly" & "/auth/contacts.readonly"

最佳答案

可以引用如下语法:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PLUS_LOGIN)) // "https://www.googleapis.com/auth/plus.login"
                .requestScopes(new Scope(Scopes.PLUS_ME)) // "https://www.googleapis.com/auth/plus.me"
                .requestEmail()
                .build();

更多详情请访问 this documentation .希望对您有所帮助!

关于android - 无法在 Android 上设置范围 Google 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34690310/

相关文章:

android - 将 ListView 更改为 ExpandableListView

node.js - 将我的curl POST 转换为 Node JS OAuth2 token 请求

java - Android - 使用 Java 泛型返回派生类的 ArrayList

android - 不管 UUID 是什么,连接的 BluetoothSocket RFCOMM channel 是否唯一?

Codeigniter 与 google oauth2 添加主题标签 php 来重定向 ('usercp' )

php - Google 表格 API v4 创建表格并邀请用户

oauth - Google OAuth 2.0 SignIn API 请求联系人权限

salesforce - 如何在 salesforce 的 OAuth 2.0 中刷新 access_token

azure-active-directory - AADSTS70002:验证凭据时出错。 AADSTS50126:无效的用户名或密码

java - Android应用程序崩溃: FATAL EXCEPTION: main