Google People API在scopes.profile中出现性别错误

高飞飞

首先,我实际上想从旧方法获取性别,但是它说已经过时了,并且在getGender()时出现错误;无法识别

GoogleSignInAccount acct = result.getSignInAccount();
Intent Home=new Intent(this,HomeActivity.class);
            Home.putExtra("name",acct.getDisplayName());
            Home.putExtra("email", acct.getEmail());
            Home.putExtra("URL",acct.getPhotoUrl());
            Home.putExtra("URL",acct.getGender()); // cannot resolve method
            startActivity(Home);

然后我在这里搜索并感到惊讶,因为我找不到关于此People API的很多主题,尽管一个受欢迎的答案是来自isabella chen:

    /** Global instance of the HTTP transport. */
private static HttpTransport HTTP_TRANSPORT = AndroidHttp.newCompatibleTransport();
/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

// On worker thread
GoogleAccountCredential credential =
         GoogleAccountCredential.usingOAuth2(MainActivity.this, Scopes.PROFILE);
credential.setSelectedAccount(
        new Account(googleSignInAccount.getEmail(), "com.google"));
People service = new People.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                .setApplicationName(APPLICATION_NAME /* whatever you like */) 
                .build();
// All the person details
Person meProfile = service.people().get("people/me").execute();
// e.g. Gender
List<Gender> genders = meProfile.getGenders();
String gender = null;
if (genders != null && genders.size() > 0) {
    gender = genders.get(0).getValue();
}

我尝试重用代码,但在Scopes.PROFILES遇到错误,它说错了第二类型参数...,我不明白。

这是我的谷歌代码:

            //Initializing google signin option
        gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PLUS_LOGIN))
                .requestScopes(new Scope(Scopes.PROFILE))
                .requestProfile()
                .requestEmail()
                .build();


        gplus_button = (SignInButton) findViewById(R.id.sign_in_button);
        gplus_button.setSize(SignInButton.SIZE_STANDARD);
        gplus_button.setScopes(gso.getScopeArray());

        //Initializing google api client
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .addApi(Plus.API)
                .build();

我会使用任何可行的方法,即使是已弃用的方法,不幸的是我在两种方法上都会出错。

编辑明确的问题:

不建议使用的方法错误:getGender()中的错误;,无法解决方法

更新的方法:Scopes.PROFILE中的错误,android studio中的红色下划线表示错误的2nd type参数。找到'java.lang.String'必需的类型'java.util.Collection'

高飞飞

我想我找到了解决方案。

我需要对Scopes.PROFILE使用collection / array。

Collection<String> scopes = new ArrayList<>(Collections.singletonList(Scopes.PROFILE));
GoogleAccountCredential credential = 
                    GoogleAccountCredential.usingOAuth2(MainActivity.this, scopes);

现在工作了。谢谢

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

通过Google People API的性别

Google People API注释

Google Contacts API与People API

不建议使用Google Plus API。我如何从requestScopes(Scope(Scopes.PROFILE))获取性别和出生日期

Google People API未经授权

PHP中的Google People API

Google API:People vs PeopleService

获取Google People个人资料API不会返回生日和性别键值

在 Google Apps Script 中使用 Google People API 删除联系人返回 404 错误

Google People API是否支持查询功能

无法使用Google People API更新照片

Google People API / 方法:contactGroups.list

Google People API 作为 Worker/CLI

尝试访问Google API时Java中出现JSON错误

在JavaScript中的Google Transliterate API中出现错误

使用 Google People API 未显示 Google 联系人

google people.api,people.getBatchGet,如何建立resourceNames清单?

C#Google People API,peopleRequest缺少的PersonFields属性

结合使用Google People API和服务帐户

Google People API Javascript - 将 GivenName 存储为变量

Google People API是否提供查询或搜索功能?

Google People API“请求掩码不能为空”

无法使用 Google Apps 脚本更新 contactusgin People api

Google People API连接列表返回空响应

使用Angular从Google People API获取名称

Google People API 中 Person 对象的空引用异常

在 google Bigquery API 中出现间歇性 404 Not Found 错误

支持Google Contacts API多长时间?是否打算将Google People API替换?

Microsoft Graph People API-获取请求/ me / people / {id}中的错误