标签:android google-plus google-oauth
此处列出了Google授权范围列表:https://developers.google.com/+/api/oauth.很好……
在Android客户端的QuickStart示例中,获取GoogleApiClient实例的代码如下所示,但具有“Plus.SCOPE_PLUS_LOGIN”范围.但我希望改为使用“电子邮件”范围.我无法找到“电子邮件”范围的常量.
private GoogleApiClient buildGoogleApiClient() {
// When we build the GoogleApiClient we specify where connected and
// connection failed callbacks should be returned, which Google APIs our
// app uses and which OAuth 2.0 scopes our app requests.
return new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, Plus.PlusOptions.builder().build())
.addScope(Plus.SCOPE_PLUS_LOGIN) // I WANT AN email SCOPE!!!
.build();
}
我是否必须自己创建Scope实例?例如:
Scope emailScope = new Scope("email"); // like this?????
解决方法:
您可以使用Plus.AccountApi.getAccountName()来检索登录用户的电子邮件地址:
// Note mGoogleApiClient must be connected for this to work
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
根据开发人员文档的一个注释:
Gets the account name resolved by Google Play services. The permission
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
must be declared in yourAndroidManifest.xml
to use this method.
标签:android,google-plus,google-oauth 来源: https://codeday.me/bug/20190624/1277819.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。