Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch email addresses of Google plus circles (Friends added in Google plus circles)

I am able to login with google plus and have fetch the list of all the people who are in my google plus circle but now i also want to get the email addresses of all people in my circle is there are way to do it? I have tried this code but it does not work.

public void onPeopleLoaded(ConnectionResult status, final PersonBuffer personBuffer,
            String nextPageToken) 
    {
        if (status.getErrorCode() == ConnectionResult.SUCCESS) 
        {           
            try
            {
                //Add all friends ids in an arraylist
                int count = personBuffer.getCount();
                //Loop through all the ids of google plus friends
                for (int i = 0; i < count; i++) 
                {
                    //mListItems.add(personBuffer.get(i).getDisplayName());
                    //mListIds.add(personBuffer.get(i).getId());  

                    friends_gplus_Ids += personBuffer.get(i).getId() + ",";
                    //Log.d("Emails", personBuffer.get(i).getOrganizations().toString());
                    //personBuffer.get(i).getEmails().size();

                    if((personBuffer.get(i).getEmails().size() > 0)) 
                    {
                        Log.d("Emails", personBuffer.get(i).getEmails().get(0).toString());
                    }
                    else
                    {
                        Log.d("Emails", "Null");
                    }                                   
                }
            }
            finally
            {
                personBuffer.close(); 
            }
}
like image 534
Nouman Bhatti Avatar asked Nov 12 '22 21:11

Nouman Bhatti


1 Answers

You would probably need to request both the Google+ scopes and the Contacts API scope (https://www.google.com/m8/feeds). You would then need to request the user's contacts and find those with Google+ profile URLs, which will look something like:

<gContact:website href='http://www.google.com/profiles/1234567890' rel='profile'/>

Then you'd look to see if an email address also existed for that contact as a sibling element.

like image 152
BrettJ Avatar answered Nov 15 '22 00:11

BrettJ