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

Got 400, OAuth2Exception: error" : "invalid_request #162

Closed
litan1106 opened this issue Aug 31, 2016 · 40 comments
Closed

Got 400, OAuth2Exception: error" : "invalid_request #162

litan1106 opened this issue Aug 31, 2016 · 40 comments
Assignees

Comments

@litan1106
Copy link

OAuth2Exception {#350

message: """

{\n
"error" : "invalid_request"\n
}
"""

code: 400

file: "src/Google/Api/Ads/Common/Util/SimpleOAuth2Handler.php"

@kwitte
Copy link

kwitte commented Aug 31, 2016

Same issue here.

auth.ini is apparently out of date.

"installed application" is no longer even a type. Google's choices now offered are:

  • Web application
  • Android Learn more
  • Chrome App Learn more
  • iOS Learn more
  • PlayStation 4
  • Other

@vtsao
Copy link
Contributor

vtsao commented Aug 31, 2016

Hi @litan1106 - I'll need some more information. Are you using existing OAuth2 credentials that were previously working and have stopped working? Or are you trying to create new ones? Which version of the client library are you using?

@kwitte can you describe your situation in more detail as well? The documentation in auth.ini is out of date, yes, and thanks for reporting it, I'll look into fixing it. It's now known as "other" in the dev console.

Thanks,
Vincent

@vtsao vtsao self-assigned this Aug 31, 2016
@kwitte
Copy link

kwitte commented Aug 31, 2016

Hi @vtsao
Something appears to be down on the Google oauth server farm. Requests are being dropped: http://youtu.be/LyMyQ1_4Pgs

[ ...switched to experimental API, thank you @vtsao ... ]

@alancoleman
Copy link

Hi Everyone,

I'm receiving the same intermittent error in my logs (See below).

Our OAuth2 Credentials do still seem to be working apart from the intermittent issue.

Library: googleads-php-lib-10
Version: v201605

Time of first error: 30-Aug-2016 10:15:03 America/Denver
Time of most recent error: 01-Sep-2016 02:20:04 America/Denver

Thank you.

[30-Aug-2016 13:15:04 America/Denver] PHP Fatal error: Uncaught exception 'OAuth2Exception' with message '{
"error" : "invalid_request"
}' in /home2/adwordsl/public_html/app/googleads-php-lib-10/src/Google/Api/Ads/Common/Util/SimpleOAuth2Handler.php:133
Stack trace:
#0 /home2/adwordsl/public_html/app/googleads-php-lib-10/src/Google/Api/Ads/Common/Util/SimpleOAuth2Handler.php(96): SimpleOAuth2Handler->MakeRequest('https://account...', Array)
#1 /home2/adwordsl/public_html/app/googleads-php-lib-10/src/Google/Api/Ads/Common/Util/OAuth2Handler.php(116): SimpleOAuth2Handler->RefreshAccessToken(Array)
#2 /home2/adwordsl/public_html/app/googleads-php-lib-10/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php(452): OAuth2Handler->GetOrRefreshAccessToken(Array)
#3 /home2/adwordsl/public_html/app/googleads-php-lib-10/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php(199): AdsSoapClient->GenerateHttpHeaders()
#4 /home2/adwordsl/public_html/app/googleads-php-lib-10/src/Google/Api/Ads/AdWords/Lib/AdWordsSoapClient.php(86): AdsSoapClient->__soapCall('get', Array)
#5 /home2/adwords in /home2/adwordsl/public_html/app/googleads-php-lib-10/src/Google/Api/Ads/Common/Util/SimpleOAuth2Handler.php on line 133

@litan1106
Copy link
Author

@kwitte is the experimental API oauth works fine for you?

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

I'm looking into it. Are you guys using AdWords or DFP? Can you give me an example of what service you're calling? I'll try to reproduce.

@litan1106
Copy link
Author

I am calling the AdWords API - CustomerService using the v12.0.0 php library.

// constructor stuff
$this->adWordsUser = $adWordsUser;
// Set our AdWords auth.ini
$adWordsUser->__construct($authenticationIniPath = base_path('adwords-auth.ini'));

// method stuff
$this->adWordsUser->LogAll();
$this->adWordsUser->SetClientCustomerId($cid);

// Get the Manage Customer Service
$managedCustomerService = $this->adWordsUser->GetService('CustomerService', 'v201607');

try {
$result = $managedCustomerService->getCustomers();

dd($result);

} catch (Exception $e) {
dd($e);
}

@kwitte
Copy link

kwitte commented Sep 1, 2016

@litan1106 Yes sir!

Now using experimental API with JSON credentials file and service account.

(@vtsao Was previously using DFP v201605 LineItemService call via API 10.1.0 and using OAuth client_id/client_secret. Intermittent "invalid_request" error also popped up trying to get a new token as well occassionally.)

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

To confirm - this is happening when you're running code from a local machine right? And not just an AWS instance or something like that?

@ivycheung
Copy link

I'm glad someone also came across this error. I was going to create an issue if I still didn't see one this morning. I ran into the same issue the past two days. I exhausted my options with Google and StackOverflow.

Library: googleads-php-lib-12
Version: v201607

It is intermittent in terms of failing 5 times in a row, then working a few times in a row then failing again.

exception 'OAuth2Exception' with message '{
"error" : "invalid_request"
}' in /[...]/googleads-php-lib/src/Google/Api/Ads/Common/Util/SimpleOAuth2Handler.php:119
Stack trace:
#0 /[...]/googleads-php-lib/src/Google/Api/Ads/Common/Util/SimpleOAuth2Handler.php(96): SimpleOAuth2Handler->MakeRequest('https://account...', Array)
#1 /[...]/googleads-php-lib/src/Google/Api/Ads/Common/Util/OAuth2Handler.php(116): SimpleOAuth2Handler->RefreshAccessToken(Array)
#2 /[...]/googleads-php-lib/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php(452): OAuth2Handler->GetOrRefreshAccessToken(Array)
#3 /[...]/googleads-php-lib/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php(199): AdsSoapClient->GenerateHttpHeaders()
#4 /[...]/googleads-php-lib/src/Google/Api/Ads/AdWords/Lib/AdWordsSoapClient.php(86): AdsSoapClient->__soapCall('get', Array)
#5 /[...]/googleads-php-lib/src/Google/Api/Ads/AdWords/v201607/ManagedCustomerService.php(4573): AdWordsSoapClient->__soapCall('get', Array)
#6 /[...].job.php(206): ManagedCustomerService->get(Object(Selector))
#7 /[...].job.php(39): Derelicte_AdWords_Data_Job->_get_all_accounts_and_labels(Object(AdWordsUser))
#8 /[...].job.php(562): Derelicte_AdWords_Data_Job->run()
#9 {main}2016-08-31 11:52:23 ip-10-41-5-172 [...].job[5388] - ERROR: EXIT! There was a OAuth2Exception error 400:{
"error" : "invalid_request"
}

I pass in my ini file into the user object and I've used it to call
$managed_customer_service = $user->GetService('ManagedCustomerService', ADWORDS_VERSION); and $labelService = $user->GetService('LabelService', ADWORDS_VERSION); for example.

@kwitte
Copy link

kwitte commented Sep 1, 2016

@vtsao Never tried from my local machine yesterday. All my 10.1.0 calls always originated from the same single AWS instance (no caching, no multi-host DNS records, no load balancing -- just a bare instance). My experimental API is installed on a different AWS instance. You are a hero for offering to look into this for everyone.

@litan1106
Copy link
Author

@vtsao I have two vps instances running in the cloud. And one local instances running in a vagrant. They all got the same error in every other request. OAuth2Exception: error" : "invalid_request"

I tried the same request for 5 times, 1 of 5 request worked and got the data from AdWords API. Other 4 requests failed with OAuth2Exception: error" : "invalid_request"

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

Thanks for the info all. I'm still unable to reproduce the issue. But since it seems like it's specific to the PHP client library (and works in the experimental version), the only thing I can see so far is that the OAuth2Handler is using an older access token OAuth2 endpoint:
https://github.com/googleads/googleads-php-lib/blob/master/src/Google/Api/Ads/Common/Util/OAuth2Handler.php#L43

Can you guys try manually updating it to this one:
https://www.googleapis.com/oauth2/v4/token

for now and see if these issues stop?

Reference: https://developers.google.com/identity/protocols/OAuth2InstalledApp#refresh

@kwitte
Copy link

kwitte commented Sep 1, 2016

@vtsao I get "Error 400 (Not Found)" after I supply my API 10.1.0 GetRefreshToken.php on yesterday's server with the new success code provided by the URL it directs me to. But I only changed the ACCESS_ENDPOINT. Should I change AUTHORIZE_ENDPOINT as well to a v4 URL?

screen shot 2016-09-01 at 9 35 31 am

@litan1106
Copy link
Author

@vtsao I got 400 after I changed

const ACCESS_ENDPOINT = 'https://www.googleapis.com/oauth2/v4/token';

@litan1106
Copy link
Author

curl 'https://www.googleapis.com/oauth2/v4/token' -d 'grant_type=refresh_token&refresh_token=<insert_refresh_token_here>&client_id=<insert_client_id_here>&client_secret=<insert_client_secret_here>

I tried the curl with my credential. It worked for me and I got access token from it.

{
"access_token": "xxxx",
"token_type": "Bearer",
"expires_in": 3600
}

@litan1106
Copy link
Author

I did ten of the curl request, I got access token without error.

{
"access_token": "xxx",
"token_type": "Bearer",
"expires_in": 3600
}

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

Thanks @litan1106 it might be a CurlUtils issue with the client library. Let me examine that.

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

What version of PHP are you guys using?

@kwitte
Copy link

kwitte commented Sep 1, 2016

my 10.1.0 API on a server running PHP 5.3.10-1ubuntu3.8 with Suhosin-Patch (cli)

@litan1106
Copy link
Author

I am running 12.0.0 with AdWords V201607

"googleads/googleads-php-lib": "~12.0.0",

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

@litan1106 what version of PHP specifically are you running?

@litan1106
Copy link
Author

@vtsao PHP 7.0.5-2+deb.sury.org~trusty+1

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

Which region are you guys located in, or where are your servers based?

@gregoryagrant
Copy link

gregoryagrant commented Sep 1, 2016

same issue here I am running 12.0.0 with adwords v201607 php 5.6 and having random oath issues, sometimes it works fine other times it fails with 400 issue. I am hosting on ec2

@kwitte
Copy link

kwitte commented Sep 1, 2016

@vtsao my 10.1.0 API on an EC2 server running in us-west-1. My experimental API (which has not yet experienced any issues) runs on an EC2 server running in us-east-1.

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

@gregoryagrant can you try making some requests from your local machine to see if you encounter this error as well? I'm still unable to reproduce this issue, so trying to isolate variables.

@gregoryagrant
Copy link

the weird thing is, it works on my local windows 10 machine running php on xamp and I cannot reproduce this issue. The server it is running on is running Ubuntu 14.0 serving the application over apache 2

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

Can you try curling to:
https://accounts.google.com/o/oauth2/token

curl 'https://accounts.google.com/o/oauth2/token' -d 'grant_type=refresh_token&refresh_token=&client_id=&client_secret=

from your EC2 instance and see if you can reproduce.

@gregoryagrant
Copy link

{
"access_token" : "got the data here",
"token_type" : "Bearer",
"expires_in" : 3600
}

@kwitte
Copy link

kwitte commented Sep 1, 2016

@vtsao Your curl command works flawlessly. Meanwhile, on same 10.1.0 server, LineItemService call from yesterday (after undoing your v4 endpoint suggestion) still yields intermittent errors.

@gregoryagrant
Copy link

yeah that is what is bugging me. And the errors are random. It does not happen after each call, it's like these 3 work then the other one dies with oauth issue.

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

Can one of you run a tcpdump on a request that is failing and we will inspect it. You can send it to us at dfpapi-support@google.com.

@litan1106
Copy link
Author

@vtsao I did ten curl requests with the same credentials. No error.

curl 'https://accounts.google.com/o/oauth2/token' -d 'grant_type=refresh_token&refresh_token=&client_id=&client_secret=

@vtsao
Copy link
Contributor

vtsao commented Sep 1, 2016

Thanks for the information all, we're still investigating this.

@markvaneijk
Copy link

I had yesterday multiple times the "invalid_request" error with OAuth2Exception, while sending thousands of API requests that day.

But today it's going smooth again. So maybe it was just a occasional hick up on the Google servers?

@alancoleman
Copy link

The last error I received was yesterday - 01-Sep-2016 17:20:04 America/Denver

like @markvaneijk I'm running requests continually throughout the day and as yet haven't received the error.

@litan1106
Copy link
Author

Thanks for the help. The issue has been fixed by the Google Team.

@ivycheung
Copy link

Thank you! I have no admin rights to test anything other than my own code so I had to twiddle my thumbs and hope everyone could resolve this.

@vtsao
Copy link
Contributor

vtsao commented Sep 2, 2016

Thanks for everybody's patience on this and helping out with providing us with information. This was caused by something we were rolling out on our end, that has been reverted now.

This client library also wasn't handling the HTTP POST correctly for refreshing an access token. It was sending the HTTP POST as form-data, when it should have just been a regular POST. That's been fixed in the 13.0.0 release:
https://github.com/googleads/googleads-php-lib/releases/tag/13.0.0

Would highly recommend updating to this release.

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

8 participants
@kwitte @vtsao @ivycheung @alancoleman @litan1106 @markvaneijk @gregoryagrant and others