title: how to solve access_token in OAuth 2.0
body: <p>i am working on getting logged user details.
   it is appear following the error.</p>
  
  <p>Notice: Undefined property: stdClass::$access_token in C:\xampp\htdocs\google\oauth\validate.php on line 46</p>
  
  <p>this is my code:</p>
  
  <pre><code>&lt;?php
  //setting parameters
  $authcode= $_GET["code"];
  $clientid='my';
  $clientsecret='my';
  $redirecturi='https://localhost/google/oauth/validate.php';
  $fields=array(
  'code'=&gt;  urlencode($authcode),
  'client_id'=&gt;  urlencode($clientid),
  'client_secret'=&gt;  urlencode($clientsecret),
  'redirect_uri'=&gt;  urlencode($redirecturi),
  'grant_type'=&gt;  urlencode('authorization_code')
  );
  //url-ify the data for the POST
  $fields_string='';
  foreach($fields as $key=&gt;$value) { $fields_string .= $key.'='.$value.'&amp;'; }
  $fields_string=rtrim($fields_string,'&amp;');
  //open connection
  $ch = curl_init();
  //set the url, number of POST vars, POST data
  curl_setopt($ch,CURLOPT_URL,'https://accounts.google.com/o/oauth2/token');
  curl_setopt($ch,CURLOPT_POST,5);
  curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
  // Set so curl_exec returns the result instead of outputting it.
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  //to trust any ssl certificates
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  //execute post
  $result = curl_exec($ch);
  //close connection
  curl_close($ch);
  //extracting access_token from response string
  $response= json_decode($result);
  $accesstoken= $response-&gt;access_token;
  //passing accesstoken to obtain contact details
   $xmlresponse=  file_get_contents('https://www.google.com/m8/feeds/contacts/default /full?oauth_token='.$accesstoken);
  //reading xml using SimpleXML
  $xml=  new SimpleXMLElement($xmlresponse);
  $xml-&gt;registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
  $result = $xml-&gt;xpath('//gd:email');
  foreach ($result as $title) {
  echo $title-&gt;attributes()-&gt;address . "&lt;br&gt;&lt;br&gt;";
  }
  ?&gt;
  </code></pre>