php - Latest Google Adwords oAuth API implementation -
good day,
i having issue trying migrate adwords api oauth more recent api version v201705.
my old implementation using v201609 working, , since version has been in sunset. have been migrating app more recent api version.
basically having hard time trying find documentation google or anywhere shows how implement google oauth adwords api relevant latest adwords api versions.
below current code:
$redirecturi = 'http://xxxxxxx/dashboard/accounts/oauth2callback'; $code = $_get['code']; //$code = request::query('code'); $user = new adwordsuser( base_path('auth.ini'), null, null, null, base_path('settings.ini'), null ); $oauth2handler = $user->getoauth2handler(); // access token using authorization code. ensure use same // redirect url used when requesting authorization. $user->setoauth2info( $oauth2handler->getaccesstoken( $user->getoauth2info(), $code, $redirecturi)); // access token expires refresh token obtained offline use // doesn't, , should stored later use. //return $user->getoauth2info(); //$result = json_decode($user->getoauth2info()); $refreshtoken = $user->getoauth2info()['refresh_token'];
can point me correct implementation latest google adwords api version of this?
below have been trying achieve @ moment, not working and/or missing entirely:
$redirecturi = 'http://xxxxxxx/dashboard/accounts/oauth2callback'; $code = $_get['code']; //$code = request::query('code'); /* $user = new adwordsuser( base_path('auth.ini'), null, null, null, base_path('settings.ini'), null ); */ // generate refreshable oauth2 credential authentication. $oauth2credential = (new oauth2tokenbuilder()) ->fromfile() ->build(); // construct api session configured properties file , oauth2 // credentials above. $user = (new adwordssessionbuilder()) ->fromfile() ->withoauth2credential($oauth2credential) ->build(); $oauth2handler = $user->getoauth2handler(); // access token using authorization code. ensure use same // redirect url used when requesting authorization. $user->setoauth2info( $oauth2handler->getaccesstoken( $user->getoauth2info(), $code, $redirecturi)); // access token expires refresh token obtained offline use // doesn't, , should stored later use. //return $user->getoauth2info(); //$result = json_decode($user->getoauth2info()); $refreshtoken = $user->getoauth2info()['refresh_token']; $customer_id = $this->getclientcustomername($refreshtoken)['customer_id']; //$customer_name = $this->getclientcustomername($refreshtoken)['customer_name'];
thanks.
well, i've figured out need follow google oauth2 implementation using google adwords implementation prior. didn't knew both work same.
below have come , working:
$redirecturi = 'http://xxxxxxx/dashboard/accounts/oauth2callback'; $code = $_get['code']; $oauth2 = new oauth2([ 'authorizationuri' => 'https://accounts.google.com/o/oauth2/v2/auth', 'tokencredentialuri' => 'https://www.googleapis.com/oauth2/v4/token', 'redirecturi' => $redirecturi, 'clientid' => $this->client_id, 'clientsecret' => $this->client_secret, 'scope' => '****' ]); $oauth2->setcode($code); $authtoken = $oauth2->fetchauthtoken(); // store refresh token user in local storage if // requested offline access. $refreshtoken = $authtoken['refresh_token'];
Comments
Post a Comment