3

`require('../config.php'); require('../HttpPost.class.php'); if(isset($_GET['code'])) {

$code = $_GET['code'];
$url = 'https://accounts.google.com/o/oauth2/token';

$params = array(
    "code" => $code,
    "client_id" => $oauth2_client_id,
    "client_secret" => $oauth2_secret,
    "redirect_uri" => $oauth2_redirect,
    "grant_type" => "authorization_code"
);

$request = new HttpPost($url);
$request->setPostData($params);
$request->send();

$responseObj = json_decode($request->getHttpResponse(), true); 
$access_token = $responseObj['access_token'];`

I followed the following code when trying to post content to the timeline of glass. https://github.com/backupbrain/google-mirror-insert-timeline-php But i am getting an error on line 55 of outh2callback/index.php saying that " Trying to get property of non-object" which essentially means that there is no value in the $request->getHttpResponse()

Can anyone help me out on it as i am very new to glassware and i am trying to get hold of how things work!

Thank you !!

Chirag
  • 335
  • 2
  • 3
  • 13
  • Can you post your code ? Interesting that you are trying something new. – Shankar Narayana Damodaran Jan 29 '14 at 07:40
  • $request = new HttpPost($url); $request->setPostData($params); $request->send(); // decode the incoming string as JSON, this is line 55 $responseObj = json_decode($request->getHttpResponse()); // Tada: we have an access token! $access_token = $responseObj->access_token; – Chirag Jan 29 '14 at 07:45
  • You can access the full code at the github link i mentioned. – Chirag Jan 29 '14 at 07:51
  • Maybe you shouldn't convert JSON response to PHP object? Use it as associative array. Try this: $responseObj = json_decode($request->getHttpResponse(), true); $access_token = $responseObj['access_token']; – hindmost Jan 29 '14 at 07:53
  • I am not getting the error now, but still no value from getHttpResponse() !! – Chirag Jan 29 '14 at 11:20
  • Can you please add a bit more code by editing your question? It comes through a lot more clear than in comments :) Also, can you share the raw http response you see? (before you parse it) – mimming Jan 29 '14 at 18:35
  • I have edited the question to include the code ! config.php has the settings - client is and all ! HttpPost.class.php has the curl – Chirag Jan 31 '14 at 09:14
  • IIRC, I've had problems with Google services before when I wasn't setting the useragent. Something to do with that perhaps? – Michael Feb 03 '14 at 12:16

0 Answers0