Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6778945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:19:36+00:00 2026-05-26T16:19:36+00:00

I’m currently using this function to get all my contacts from Google Contacts. session_start();

  • 0

I’m currently using this function to get all my contacts from Google Contacts.

session_start();

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/accounts/ClientLogin');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$data = array(
    'accountType' => 'GOOGLE',
    'Email' => 'email',
    'Passwd' => 'password',
    'source'=>'sourcetest',
    'service'=>'cp'
);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);


$responses = explode("\n", curl_exec($ch));
$_SESSION['auth'] = str_replace('Auth=', '', $responses[2]);
$_SESSION['email'] = 'email';



$url = 'https://www.google.com/m8/feeds/contacts/default/full';
$url .= '?group=http://www.google.com/m8/feeds/groups/'.$_SESSION['email'].'/base/6';
$url .= '&max-results=500&alt=json';

$ch = curl_init($url);

$header[] = 'Authorization: GoogleLogin auth='.$_SESSION['auth'];
$header[] = 'GData-Version: 3.0';

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);

$response = curl_exec($ch);
curl_close($ch);

To print the whole JSON works fine with echo $respone; but I don’t know how to list all of the contacts (full name, phone and image/avatar) in a table. I have tried json_decode() and even Google’d for a solution for a few days now with no result.

I’m asking you know – how can I fix this?

Thanks in advance.

EDIT

Array
(
    [version] => 1.0
    [encoding] => UTF-8
    [feed] => Array
        (
            [xmlns] => http://www.w3.org/2005/Atom
            [xmlns$openSearch] => http://a9.com/-/spec/opensearch/1.1/
            [xmlns$gContact] => http://schemas.google.com/contact/2008
            [xmlns$batch] => http://schemas.google.com/gdata/batch
            [xmlns$gd] => http://schemas.google.com/g/2005
            [gd$etag] => W/"{code}"
            [id] => Array
                (
                    [$t] => mymail@gmail.com
                )

            [updated] => Array
                (
                    [$t] => 2011-11-07T13:50:54.073Z
                )

            [category] => Array
                (
                    [0] => Array
                        (
                            [scheme] => http://schemas.google.com/g/2005#kind
                            [term] => http://schemas.google.com/contact/2008#contact
                        )

                )

            [title] => Array
                (
                    [$t] => edgren's Contacts
                )

            [link] => Array
                (
                    [0] => Array
                        (
                            [rel] => alternate
                            [type] => text/html
                            [href] => http://www.google.com/
                        )

                    [1] => Array
                        (
                            [rel] => http://schemas.google.com/g/2005#feed
                            [type] => application/atom+xml
                            [href] => https://www.google.com/m8/feeds/contacts/mymail%40gmail.com/full
                        )

                    [2] => Array
                        (
                            [rel] => http://schemas.google.com/g/2005#post
                            [type] => application/atom+xml
                            [href] => https://www.google.com/m8/feeds/contacts/mymail%40gmail.com/full
                        )

                    [3] => Array
                        (
                            [rel] => http://schemas.google.com/g/2005#batch
                            [type] => application/atom+xml
                            [href] => https://www.google.com/m8/feeds/contacts/mymail%40gmail.com/full/batch
                        )

                    [4] => Array
                        (
                            [rel] => self
                            [type] => application/atom+xml
                            [href] => https://www.google.com/m8/feeds/contacts/mymail%40gmail.com/full?alt=json&max-results=500&group=http%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds%2Fgroups%2Fmymail%40gmail.com%2Fbase%2F6
                        )

                )

            [author] => Array
                (
                    [0] => Array
                        (
                            [name] => Array
                                (
                                    [$t] => edgren
                                )

                            [email] => Array
                                (
                                    [$t] => mymail@gmail.com
                                )

                        )

                )

            [generator] => Array
                (
                    [version] => 1.0
                    [uri] => http://www.google.com/m8/feeds
                    [$t] => Contacts
                )

            [openSearch$totalResults] => Array
                (
                    [$t] => 73
                )

            [openSearch$startIndex] => Array
                (
                    [$t] => 1
                )

            [openSearch$itemsPerPage] => Array
                (
                    [$t] => 500
                )

            [entry] => Array
                (
                    [0] => Array
                        (
                            [gd$etag] => "{code}"
                            [id] => Array
                                (
                                    [$t] => http://www.google.com/m8/feeds/contacts/mymail%40gmail.com/base/{code}
                                )

                            [updated] => Array
                                (
                                    [$t] => 2011-09-12T17:28:57.835Z
                                )

                            [app$edited] => Array
                                (
                                    [xmlns$app] => http://www.w3.org/2007/app
                                    [$t] => 2011-09-12T17:28:57.835Z
                                )

                            [category] => Array
                                (
                                    [0] => Array
                                        (
                                            [scheme] => http://schemas.google.com/g/2005#kind
                                            [term] => http://schemas.google.com/contact/2008#contact
                                        )

                                )

                            [title] => Array
                                (
                                    [$t] => {contacts name}
                                )

                            [link] => Array
                                (
                                    [0] => Array
                                        (
                                            [rel] => http://schemas.google.com/contacts/2008/rel#photo
                                            [type] => image/*
                                            [href] => https://www.google.com/m8/feeds/photos/media/mymail%40gmail.com/{code}
                                            [gd$etag] => "{code}"
                                        )

                                    [1] => Array
                                        (
                                            [rel] => self
                                            [type] => application/atom+xml
                                            [href] => https://www.google.com/m8/feeds/contacts/mymail%40gmail.com/full/{code}
                                        )

                                    [2] => Array
                                        (
                                            [rel] => edit
                                            [type] => application/atom+xml
                                            [href] => https://www.google.com/m8/feeds/contacts/mymail%40gmail.com/full/{code}
                                        )

                                )

                            [gd$name] => Array
                                (
                                    [gd$fullName] => Array
                                        (
                                            [$t] => {contacts name}
                                        )

                                    [gd$givenName] => Array
                                        (
                                            [$t] => {contacts last name}
                                        )

                                    [gd$familyName] => Array
                                        (
                                            [$t] => {contacts first name}
                                        )

                                )

                            [gContact$birthday] => Array
                                (
                                    [when] => {contacts birthday}
                                )

                            [gd$email] => Array
                                (
                                    [0] => Array
                                        (
                                            [rel] => http://schemas.google.com/g/2005#other
                                            [address] => {contacts email}
                                            [primary] => true
                                        )

                                )

                            [gd$phoneNumber] => Array
                                (
                                    [0] => Array
                                        (
                                            [rel] => http://schemas.google.com/g/2005#mobile
                                            [$t] => {contacts number}
                                        )

                                )

                            [gd$structuredPostalAddress] => Array
                                (
                                    [0] => Array
                                        (
                                            [rel] => http://schemas.google.com/g/2005#home
                                            [gd$formattedAddress] => Array
                                                (
                                                    [$t] => {contacts address}
                                                )

                                            [gd$street] => Array
                                                (
                                                    [$t] => {contacts address}
                                                )

                                            [gd$postcode] => Array
                                                (
                                                    [$t] => {contacts address}
                                                )

                                            [gd$city] => Array
                                                (
                                                    [$t] => {contacts address}
                                                )

                                            [gd$region] => Array
                                                (
                                                    [$t] => {contacts address}
                                                )

                                            [gd$country] => Array
                                                (
                                                    [code] => SE
                                                    [$t] => Sverige
                                                )

                                        )

                                )

                            [gContact$website] => Array
                                (
                                    [0] => Array


        (
                                        [href] => {contacts website}
                                        [rel] => profile
                                    )

                            )

                        [gd$extendedProperty] => Array
                            (
                                [0] => Array
                                    (
                                        [name] => workAddrTB
                                        [value] => WorkAddress2=/WorkCity=/WorkState=/WorkZipCode=/WorkCountry=
                                    )

                                [1] => Array
                                    (
                                        [name] => homeAddrTB
                                        [value] => HomeAddress2=/HomeCity=/HomeState=/HomeCountry=Sverige/HomeZipCode=
                                    )

                                [2] => Array
                                    (
                                        [name] => contactTB
                                        [value] => PreferMailFormat=0/allowRemoteContent=
                                    )

                            )

                        [gContact$groupMembershipInfo] => Array
                            (
                                [0] => Array
                                    (
                                        [deleted] => false
                                        [href] => http://www.google.com/m8/feeds/groups/mymail%40gmail.com/base/6
                                    )

                                [1] => Array
                                    (
                                        [deleted] => false
                                        [href] => http://www.google.com/m8/feeds/groups/mymail%40gmail.com/base/d
                                    )

                            )

                    )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:19:37+00:00Added an answer on May 26, 2026 at 4:19 pm

    Is the JSON that is returned valid? You could paste the result into JSONLint and see if it returns errors.

    json_decode() should return NULL for invalid input. Try using var_dump(json_decode($response). Does it return NULL or some other value?

    Also, you should be aware that json_decode() returns an object by default, so doing something like echo $response['somekey']; wouldn’t work. To get an associative array, use json_decode($response, true);.


    Edit: The foreach was just an example. At the time, you didn’t post any output, so I had to guess what would be returned.

    If you decode the JSON response into an array, you can iterate over the results using foreach, from your sample, it seems that the contacts are in $the_array["feed"]["entries"].

    A crude example that should to output a table, if I interpreted the sample correctly:

    <?php
    $response_as_array = json_decode($response, true);
    if(isset($response_as_array['feed']) and isset($response_as_array['feed']['entry']))
    {   
        echo '<table border="1">'. "\n";
        foreach($response_as_array['feed']['entries'] as $i = > $entry)
        {
            $info = array(
                'title'         => $entry['title'],
                'fullName'      => $entry['gd$name']['gd$fullName']['$t'],
                'givenName'     => $entry['gd$name']['gd$givenName']['$t'],
                'familyName'    => $entry['gd$name']['gd$familyName']['$t'],
                'birthday'      => $entry['gContact$birthday']['when'],
                'email'         => (isset($entry['gd$email'][0]) 
                    ? $entry['gd$email'][0]['address'] : ''),
                'phoneNumber'   => (isset($entry['gd$phoneNumber'][0]) 
                    ? $entry['gd$phoneNumber'][0][$t] : ''),
                // and so on
            );
    
            // If this is the first time this loop is run, 
            // then we want to output the column names.
            if($i === 0) {
                echo '<tr>'. "\n";
                foreach(array_keys($info) as $column_name) {
                    echo '<th>'. $column_name .'</th>';
                }
                echo '</tr>' . "\n";
            }
    
            echo '<tr>'. "\n";
            foreach($info as $value) {
                echo '<td>'. $value .'</td>'. "\n";
            }
            echo '</tr>'. "\n";
        }
        echo '</table>'. "\n";
    }
    

    Note that you can’t use double quotes around the keys (such as $entry[“gd$name”]) unless you escape them like so: $entry[“gd\$name”]. If you use single quotes, you won’t have to do that.

    If the API doesn’t always return all fields (for example, if you haven’t filled in a birthdate for the user, the API might return an empty field or it might not return the gContact$birthday object/ array at all. In that case, you’ll need to build in some checks that double-check that a field exists before trying to get the value, of course. Otherwise, you’d get warnings or errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.