Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when i first call the API, #270

Closed
kelelee opened this issue Apr 2, 2017 · 14 comments
Closed

when i first call the API, #270

kelelee opened this issue Apr 2, 2017 · 14 comments
Assignees

Comments

@kelelee
Copy link

kelelee commented Apr 2, 2017

php GetCampaigns.php

PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'All of 'clientId', 'clientSecret', and 'refreshToken' must be set when using installed/web application flow.' in /src/Google/AdsApi/Common/OAuth2TokenBuilder.php:195
Stack trace:
#0 /src/Google/AdsApi/Common/OAuth2TokenBuilder.php(149): Google\AdsApi\Common\OAuth2TokenBuilder->validate()
#1 /examples/AdWords/v201609/BasicOperations/GetCampaigns.php(77): Google\AdsApi\Common\OAuth2TokenBuilder->build()
#2 /examples/AdWords/v201609/BasicOperations/GetCampaigns.php(89): Google\AdsApi\Examples\AdWords\v201609\BasicOperations\GetCampaigns::main()
#3 {main}
thrown in /src/Google/AdsApi/Common/OAuth2TokenBuilder.php on line 195

@fiboknacky
Copy link
Member

fiboknacky commented Apr 3, 2017

Hello @kelelee

How did you set the adsapi_php.ini?
It looks like you've not filled in all necessary information including clientId, clientSecret and refreshToken.
Did you miss to fill in either of them?

Best,
Knack

@kelelee
Copy link
Author

kelelee commented Apr 5, 2017

where is the file "adsapi_php.ini"? I make it at /root/adsapi_php.ini

I set the config base this url:
https://developers.google.com/adwords/api/docs/guides/first-api-call#get_an_oauth2_refresh_token_and_configure_your_client

I use the command: $ php GetRefreshToken.php
and set up the config of 'clientId', 'clientSecret',and 'refreshToken'

@fiboknacky
Copy link
Member

Hi @kelelee

As described here, it should be in the home directory of your system.
If you run this file as a different user, then this file is supposed to be place in the user's home directory, e.g., ~/adsapi_php.ini.

Best,
Knack

@fiboknacky fiboknacky self-assigned this Apr 5, 2017
@kelelee
Copy link
Author

kelelee commented Apr 5, 2017

I run this file use root , I put this file in "/root/adsapi_php.ini",it is same as "~/adsapi_php.ini",

@fiboknacky
Copy link
Member

Can you show your file contents please?
(Make sure you hide any confidential info)

Thanks.

@kelelee
Copy link
Author

kelelee commented Apr 5, 2017

the content of 'adsapi_php.ini' is:
clientId = "1034925482215-gss......nf8m.apps.googleusercontent.com"
clientSecret = "CBP.......SNMsU3e"
refreshToken = "1/Wh..hlJp_EFRX.......................w7_Vf....N_Mfi-A2pIy"

@fiboknacky
Copy link
Member

Hi,

They're needed to be under the section OAUTH2 as well to be read properly.
Could you please check that too?

And if possible, could you copy all your contents in the file, blind confidential info, and put them here?

Cheers,
Knack

@kelelee
Copy link
Author

kelelee commented Apr 5, 2017

the contents of the file "OAuth2TokenBuilder.php":

configurationLoader = new ConfigurationLoader(); } /** * @see AdsBuilder::fromFile() */ public function fromFile($path = null) { if ($path === null) { $path = self::DEFAULT_CONFIGURATION_FILENAME; } return $this->from($this->configurationLoader->fromFile($path)); } /** * @see AdsBuilder::from() */ public function from(Configuration $configuration) { $this->jsonKeyFilePath = $configuration->getConfiguration('jsonKeyFilePath', 'OAUTH2'); $this->scopes = $configuration->getConfiguration('scopes', 'OAUTH2'); $this->impersonatedEmail = $configuration->getConfiguration('impersonatedEmail', 'OAUTH2'); $this->clientId = $configuration->getConfiguration('clientId', 'OAUTH2'); $this->clientSecret = $configuration->getConfiguration('clientSecret', 'OAUTH2'); $this->refreshToken = $configuration->getConfiguration('refreshToken', 'OAUTH2'); return $this; } /** * Includes an absolute path to an OAuth2 JSON key file when using service * account flow. Required and only applicable when using service account flow. * * @param string|null $jsonKeyFilePath * @return OAuth2TokenBuilder this builder */ public function withJsonKeyFilePath($jsonKeyFilePath) { $this->jsonKeyFilePath = $jsonKeyFilePath; return $this; } /** * Includes OAuth2 scopes. Required and only applicable when using service * account flow. * * @param string|null $scopes a space-delimited list of scopes * @return OAuth2TokenBuilder this builder */ public function withScopes($scopes) { $this->scopes = $scopes; return $this; } /** * Includes an email of account to impersonate when using service account * flow. Optional and only applicable when using service account flow. * * @param string|null $impersonatedEmail * @return OAuth2TokenBuilder this builder */ public function withImpersonatedEmail($impersonatedEmail) { $this->impersonatedEmail = $impersonatedEmail; return $this; } /** * Includes an OAuth2 client ID. Required when using installed application or * web application flow. * * @param string|null $clientId * @return OAuth2TokenBuilder this builder */ public function withClientId($clientId) { $this->clientId = $clientId; return $this; } /** * Includes an OAuth2 client secret. Required when using installed application * or web application flow. * * @param string|null $clientSecret * @return OAuth2TokenBuilder this builder */ public function withClientSecret($clientSecret) { $this->clientSecret = $clientSecret; return $this; } /** * Includes an OAuth2 refresh token. Required when using installed application * or web application flow. * * @param string|null $refreshToken * @return OAuth2TokenBuilder this builder */ public function withRefreshToken($refreshToken) { $this->refreshToken = $refreshToken; return $this; } /** * @see AdsBuilder::build() */ public function build() { $this->defaultOptionals(); $this->validate(); if ($this->jsonKeyFilePath !== null) { return new ServiceAccountCredentials( $this->scopes, $this->jsonKeyFilePath, $this->impersonatedEmail ); } else { return new UserRefreshCredentials( null, [ 'client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'refresh_token' => $this->refreshToken ] ); } } /** * @see AdsBuilder::defaultOptionals() */ public function defaultOptionals() { // Nothing to default for this builder. } /** * @see AdsBuilder::validate() */ public function validate() { if (($this->jsonKeyFilePath !== null || $this->scopes !== null) && ($this->clientId !== null || $this->clientSecret !== null || $this->refreshToken !== null)) { throw new InvalidArgumentException('Cannot have both service account ' . 'flow and installed/web application flow credential values set.'); } if ($this->jsonKeyFilePath !== null || $this->scopes !== null) { if ($this->jsonKeyFilePath === null || $this->scopes === null) { throw new InvalidArgumentException('Both \'jsonKeyFilePath\' and ' . '\'scopes\' must be set when using service account flow.'); } } else if ($this->clientId === null || $this->clientSecret === null || $this->refreshToken === null) { throw new InvalidArgumentException('All of \'clientId\', ' . '\'clientSecret\', and \'refreshToken\' must be set when using ' . 'installed/web application flow.'); } } /** * Gets the JSON key file path. * @return string|null */ public function getJsonKeyFilePath() { return $this->jsonKeyFilePath; } /** * Gets the scopes. * @return string|null */ public function getScopes() { return $this->scopes; } /** * Gets the impersonated email. * @return string|null */ public function getImpersonatedEmail() { return $this->impersonatedEmail; } /** * Gets the client ID. * @return string|null */ public function getClientId() { return $this->clientId; } /** * Gets the client secret. * @return string|null */ public function getClientSecret() { return $this->clientSecret; } /** * Gets the refresh token. * @return string|null */ public function getRefreshToken() { return $this->refreshToken; } }

@fiboknacky
Copy link
Member

Sorry if it's not clear. I meant the contents of your adsapi_php.ini file, stored in the /root.

@kelelee
Copy link
Author

kelelee commented Apr 5, 2017

the content of 'adsapi_php.ini' is:
clientId = "1034925482215-gssb56kaambgvks69e137pgsk9uknf8m.apps.googleusercontent.com"
clientSecret = "CBPAuFnjHbWg7QOWFSNMsU3e"
refreshToken = "1/WhWipLnhlJp_EFRXXA4dbBpLfso31G5ZsoMzROjy3e95w7_VfzUz5N_Mfi-A2pIy"

@fiboknacky
Copy link
Member

Do you mean that those three lines are all what in your adsapi_php.ini file?
If so, that's why it doesn't work. :)

I recommend to copy from our template and modify the values you need to change.
Again, they need to be under the section [OAUTH2] to work.

Hope this help.
Knack

@kelelee
Copy link
Author

kelelee commented Apr 5, 2017

thank you very much

@rathod4rathod
Copy link

@kelelee
please tell me our local url working or not on call back

@techhjork
Copy link

image
Getting this error while trying configure the API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants