Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Google People API连接始终为空_Android_Google Api Client_Google People - Fatal编程技术网

Android Google People API连接始终为空

Android Google People API连接始终为空,android,google-api-client,google-people,Android,Google Api Client,Google People,我正试图通过以下步骤运行GooglePeopleAPI。不幸的是,它总是从ListConnectionsResponse的response.getConnections()获得空连接。登录成功后,将在onActivityResult中执行以下异步任务: class PeoplesAsync extends AsyncTask<String, Void, List<String>> { @Override protected void onPreExec

我正试图通过以下步骤运行GooglePeopleAPI。不幸的是,它总是从ListConnectionsResponse的
response.getConnections()
获得空连接。登录成功后,将在onActivityResult中执行以下异步任务:

class PeoplesAsync extends AsyncTask<String, Void, List<String>> {


    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        updateUI();
    }

    @Override
    protected List<String> doInBackground(String... params) {

        List<String> nameList = new ArrayList<>();

        try {
            People peopleService = PeopleHelper.setUp(MainActivity.this, params[0]);

            ListConnectionsResponse response = peopleService.people().connections()
                    .list("people/me").setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers")
                    .execute();
            List<Person> connections = response.getConnections();

            //error: connections is always null
            for (Person person : connections) {
                if (!person.isEmpty()) {
                    List<Name> names = person.getNames();
                    List<EmailAddress> emailAddresses = person.getEmailAddresses();
                    List<PhoneNumber> phoneNumbers = person.getPhoneNumbers();

                    if (phoneNumbers != null)
                        for (PhoneNumber phoneNumber : phoneNumbers)
                            Log.d(TAG, "phone: " + phoneNumber.getValue());

                    if (emailAddresses != null)
                        for (EmailAddress emailAddress : emailAddresses)
                            Log.d(TAG, "email: " + emailAddress.getValue());

                    if (names != null)
                        for (Name name : names)
                            nameList.add(name.getDisplayName());

                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        return nameList;
    }


    @Override
    protected void onPostExecute(List<String> nameList) {
        super.onPostExecute(nameList);

        progressBar.setVisibility(View.GONE);

        recyclerView.setVisibility(View.VISIBLE);

        adapter = new PeopleAdapter(nameList);
        recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
        recyclerView.setAdapter(adapter);

    }
}
class PeopleAsync扩展了AsyncTask{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
updateUI();
}
@凌驾
受保护列表doInBackground(字符串…参数){
列表名称列表=新的ArrayList();
试一试{
peopleService=PeopleHelper.setUp(MainActivity.this,参数[0]);
ListConnectionsResponse=peopleService.people().connections()
.list(“people/me”).setRequestMaskIncludeField(“person.name,person.emailaddress,person.phonenumber”)
.execute();
List connections=response.getConnections();
//错误:连接总是空的
用于(个人:连接){
如果(!person.isEmpty()){
列表名称=person.getNames();
List emailAddresses=person.getEmailAddresses();
List phoneNumbers=person.getPhoneNumbers();
if(电话号码!=null)
用于(电话号码电话号码:电话号码)
Log.d(标记“phone:+phoneNumber.getValue());
如果(电子邮件地址!=null)
用于(电子邮件地址电子邮件地址:电子邮件地址)
Log.d(标记“email:+emailAddress.getValue());
如果(名称!=null)
用于(名称:名称)
nameList.add(name.getDisplayName());
}
}
}捕获(IOE异常){
e、 printStackTrace();
}
返回姓名列表;
}
@凌驾
受保护的void onPostExecute(列表名称列表){
super.onPostExecute(名称列表);
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
适配器=新的适配器(名称列表);
setLayoutManager(新的LinearLayoutManager(MainActivity.this));
recyclerView.setAdapter(适配器);
}
}

Google People API中出现空响应连接的原因是什么?如何修复?您是否创建了API控制台项目?我发现了一个类似API的教程

真是一个误解,
ListConnectionsResponse=peopleService.people().connections().list(“people/me”)
不是用于用户配置文件,而是用于用户连接配置文件。如果您需要用户的个人资料信息:

Person profile = peopleService.people().get("people/me").execute();

            if (!profile.isEmpty()) {

                List<Name> names = profile.getNames();
                List<Birthday> birthdays = profile.getBirthdays();
                List<Gender> genders = profile.getGenders();
                List<Url> urls = profile.getUrls();
                List<EmailAddress> emailAddresses = profile.getEmailAddresses();
                List<Photo> profileImages = profile.getPhotos();

                String displayName = names.get(0).getDisplayName();
                String birthday = birthdays.get(0).getText();
                String gender = genders.get(0).getValue();
                String email = emailAddresses.get(0).getValue();
                String profileImage = profileImages.get(0).getUrl();

            }
Person profile=peopleService.people().get(“people/me”).execute();
如果(!profile.isEmpty()){
列表名称=profile.getNames();
List birthdays=profile.getBirthdays();
List genders=profile.getGenders();
列表URL=profile.getURL();
List emailAddresses=profile.getEmailAddresses();
List profileImages=profile.getPhotos();
字符串displayName=names.get(0).getDisplayName();
字符串birthday=birthdays.get(0.getText();
字符串gender=genders.get(0.getValue();
字符串email=emailAddresses.get(0).getValue();
String profileImage=profileImages.get(0.getUrl();
}

但为什么response.getConnections()仍然存在;问题中为空?当列表中没有朋友时,我相信我得到的是空字符串。我正在使用你的代码。我得到了姓名、ImageUrl和电子邮件ID,但其他字段返回为空。你能帮我吗?@JayDangar你在你的帐户中输入了这些字段吗?@BeeingJk,我提供了客户和秘密ID,但没有用。