php - Google+ login api problems -
i'm trying implement google+ oauth2 login in app , running few issues.
i next written here
it seems illustration using lot of libraries twig, i'm using maining pure php, , don't think part causing errors
the first issue faced google_httprequest not found
. read somewhere composer names google_http_request
, changed , seemed have fixed problem.
then php complaining making static phone call on nonstatic function getio()
. changed ::
->
because made sense me.
then getting error
php fatal error: phone call undefined method google_io_curl::authenticatedrequest()
which has changed.
the code running
$google = new google_client(); $google->setapplicationname('hamster weebly'); $google->setclientid('clientid'); $google->setclientsecret('himitsudesuyo'); $google->setredirecturi('postmessage'); $google->authenticate($_post['auth_code']); $token = json_decode($google->getaccesstoken()); //$attrbutes = $google->verifyidtoken($token->id_token, '375022219321-us60lmg2cmeoj1aqpl784t7pbl1kg3jv.apps.googleusercontent.com')->getattributes(); //error_log($attrbutes['payload']['sub']); $requrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' . $token->access_token; $req = new google_http_request($requrl); $tokeninfo = json_decode($google->getio()->authenticatedrequest($req)->getresponsebody()); if ($token->error) { http_response_code(500); exit; } // create sure token got intended user. if ($tokeninfo->userid != $gplusid) { http_response_code(401); echo json_encode("token's user id doesn't match given user id"); exit; } // create sure token got our app. if ($tokeninfo->audience != client_id) { http_response_code(401); echo json_encode("token's client id not match app"); exit; }
what issue?
in line:
$tokeninfo = json_decode($google->getio()->authenticatedrequest($req)->getresponsebody());
getio()
should changed getauth()
due (i think) migration within api.
after that, encountered error in changed: if ($token->error)
if ( isset($tokeninfo->error) )
good luck!
php oauth google-plus
No comments:
Post a Comment