title: How can I retrieve all google Contacts with the Contacts API?
body: <p>I'm trying to use the Contacts API to retrieve all the contacts of the person who clicks on the <code>&lt;a&gt;</code> at the bottom of response-callback.php. I am using Google App Engine and within the GAE I enabled the Contacts API. I got this code by following a tutorial so it's rather hard to find errors myself. I haven't worked with either PHP or GAE or any API. This also why I can't debug and check if certain values are empty are not. </p>
  
  <p>When I start the website up. I doesn't show anything. Not even the echo I am using to test if I can reach the response-callback.php nor the H2 is showing I just get a completely white page.</p>
  
  <p>app.yaml:</p>
  
  <pre><code>application: csimporttest
  version: 1
  runtime: php55
  api_version: 1
  threadsafe: yes
  
  handlers:
  
  - url: /
    script: main.php;
  </code></pre>
  
  <p>main.php:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h2&gt;Hi! Stackoverflow!&lt;/h2&gt;
  &lt;?php include'response-callback.php';
  echo "response-callback file: " $test; 
  ?&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>response-callback.php:</p>
  
  <pre><code>&lt;?php
  session_start();
  
  require_once 'google-api-php-client/src/autoload.php';
  
  $test = 'WORKS!'; 
  
  $google_client_id = 'SECRET';
  $google_client_secret = 'SECRET';
  $google_redirect_uri = 'SECRET';
  
  //setup new google client
  $client = new Google_Client();
  $client -&gt; setApplicationName('csimporttest');
  $client -&gt; setClientid($google_client_id);
  $client -&gt; setClientSecret($google_client_secret);
  $client -&gt; setRedirectUri($google_redirect_uri);
  $client -&gt; setAccessType('online');
  
  $client -&gt; setScopes('https://www.googleapis.com/auth/contacts.readonly');
  
  $googleImportUrl = $client -&gt; createAuthUrl();
  function curl($url, $post = "") {
   $curl = curl_init();
   $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
   curl_setopt($curl, CURLOPT_URL, $url);
   //The URL to fetch. This can also be set when initializing a session with curl_init().
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
   //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
   curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
   //The number of seconds to wait while trying to connect.
   if ($post != "") {
   curl_setopt($curl, CURLOPT_POST, 5);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
   }
   curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
   //The contents of the "User-Agent: " header to be used in a HTTP request.
   curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
   //To follow any "Location: " header that the server sends as part of the HTTP header.
   curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE);
   //To automatically set the Referer: field in requests where it follows a Location: redirect.
   curl_setopt($curl, CURLOPT_TIMEOUT, 10);
   //The maximum number of seconds to allow cURL functions to execute.
   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
   //To stop cURL from verifying the peer's certificate.
   $contents = curl_exec($curl);
   curl_close($curl);
   return $contents;
  }
  if(isset($_SESSION['google_code'])) {
   $auth_code = $_SESSION['google_code'];
   $max_results = 200;
      $fields=array(
          'code'=&gt;  urlencode($auth_code),
          'client_id'=&gt;  urlencode($google_client_id),
          'client_secret'=&gt;  urlencode($google_client_secret),
          'redirect_uri'=&gt;  urlencode($google_redirect_uri),
          'grant_type'=&gt;  urlencode('authorization_code')
      );
      $post = '';
      foreach($fields as $key=&gt;$value)
      {
          $post .= $key.'='.$value.'&amp;';
      }
      $post = rtrim($post,'&amp;');
      $result = curl('https://www.googleapis.com/oauth2/v4/token',$post);
      $response =  json_decode($result);
      $accesstoken = $response-&gt;access_token;
      $url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&amp;alt=json&amp;v=3.0&amp;oauth_token='.$accesstoken;
      $xmlresponse =  curl($url);
      $contacts = json_decode($xmlresponse,true);
  
   $return = array();
   if (!empty($contacts['feed']['entry'])) {
   foreach($contacts['feed']['entry'] as $contact) {
             //retrieve Name and email address  
   $return[] = array (
   'name'=&gt; $contact['title']['$t'],
   'email' =&gt; $contact['gd$email'][0]['address'],
   );
   } 
   }
  
   $google_contacts = $return;
  
   unset($_SESSION['google_code']);
  
  }
  ?&gt;
  &lt;a href="&lt;?php echo $googleImportUrl; ?&gt;"&gt; Import google contacts &lt;/a&gt;
  </code></pre>