$source = 'Ads PHP Client Library Examples'; try { print 'Requesting AuthTokens '; while (TRUE) { // Repeatedly request new authTokens, to trigger a CAPTCHA challenge. $authToken = new AuthToken($email, $password, $service, $source); $value = $authToken->GetAuthToken(); print '.'; } } catch (AuthTokenException $e) { print "\n"; if ($e->GetError() == 'CaptchaRequired') { print "A CAPTCHA is required.\n"; printf("View CAPTCHA challenge image: %s/accounts/%s\n", $authToken->GetServer(), $e->GetCaptchaUrl()); $captchaToken = $e->GetCaptchaToken(); $captchaResponse = readInput('Enter CAPTCHA response: '); // Request new AuthToken using CAPTCHA token and response. try { $authToken = new AuthToken($email, $password, $service, $source, NULL, NULL, $captchaToken, $captchaResponse); $value = $authToken->GetAuthToken(); print "CAPTCHA challenge passed.\n"; } catch (AuthTokenException $e) { print "CAPTCHA challenge failed.\n"; } } else { printf("AuthTokenException: %s\n", $e->GetError()); } } } catch (Exception $e) { print $e->getMessage(); }
/** * Regenerates the authentication token and sets it for this user. * @param string $server The server to retrieve the token from. * @return string The newly generated auth token. */ public function RegenerateAuthToken($server = NULL) { if (!isset($server)) { $server = $this->GetAuthServer(); } $authTokenClient = new AuthToken($this->email, $this->password, 'gam', $this->GetClientLibraryUserAgent(), 'GOOGLE', $server); $authToken = $authTokenClient->GetAuthToken(); $this->SetAuthToken($authToken); return $authToken; }