Hi Burak,

That's some great debugging skills! I'm glad you were able to figure out 
the root of the issue. Please file an issue 
<https://github.com/googleads/googleads-php-lib/issues> with the PHP client 
library if there is not already an issue on this.

Thanks,
Nadine, AdWords API Team

On Tuesday, December 13, 2016 at 3:35:06 PM UTC-5, Burak Karakan wrote:
>
> Little update, I think I found the root of the problem.
>
> I changed the code that makes the request in the original question with a 
> simple cURL POST call which is as follows:
>
> // Get the oAuth code.
> $authCode = $request->code;
>
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL,"https://accounts.google.com/o/oauth2/token";);
> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS, array(
>     'code' => $authCode,
>     'client_id' => $this->clientCredentials['client_id'],
>     'client_secret' => $this->clientCredentials['client_secret'],
>     'redirect_uri' => $this->callbackUrl,
>     'grant_type' => 'authorization_code'
> ));
>
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
> $server_output = curl_exec ($ch);
>
> curl_close ($ch);
>
>
>
> When I changed this, I got the following JSON response which is the same 
> error:
>
> {
>   "error" : "invalid_request"
> }
>
>
> Then I added the following lines to update the POST request headers:
>
> $headers = array(
>     'Content-Type: application/x-www-form-urlencoded'
> );
> curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
>
>
> And after this, I got the following JSON response, which had the error 
> description you mentioned:
>
>
> {
>   "error" : "invalid_request",
>   "error_description" : "Required parameter is missing: grant_type"
> }
>
>
>
> Then I did some googling, and found the solution to change the line of code 
> that sets the post fields I provided above with the method "http_build_query" 
> added to the post fields array.
>
> Complete code is this:
>
>
> // Get the oAuth code.
> $authCode = $request->code;
>
> $ch = curl_init();
>
> curl_setopt($ch, CURLOPT_URL,"https://accounts.google.com/o/oauth2/token";);
> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
>     'code' => $authCode,
>     'client_id' => $this->clientCredentials['client_id'],
>     'client_secret' => $this->clientCredentials['client_secret'],
>     'redirect_uri' => $this->callbackUrl,
>     'grant_type' => 'authorization_code'
> )));
>
> $headers = array(
>     'Content-Type: application/x-www-form-urlencoded'
> );
>
>
> curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
> $server_output = curl_exec ($ch);
>
> curl_close ($ch);
>
>
>
> After this change, I was able to get the tokens without any problem. 
>
> I just changed the request method in order to fix this, I did not change 
> anything about my client credentials, and I also used the API example files 
> to test the previous cases and all were getting the "invalid_request" 
> response without any description, even if I test with native client 
> credentials. Therefore, I believe that the error may arise because of the 
> AdWords PHP client library.
>
> We did some checks and according to our commit history, we did not change 
> even a line in our previous method, which worked with the AdWords PHP 
> library methods flawlessly for months, then started to give the error 
> "invalid_request". I think there is something wrong with the PHP library, 
> and I would like to use the library methods instead of this cURL solution, 
> which is not well structured like the library methods. As soon as the error 
> is fixed, I would like to go back to my previous methods.
>
> I don't know if this is just for our case, but I hope it does not happen 
> to anybody else.
> Looking forward to hear from you.
>
> Thanks,
> Burak.
>
>
> On Tuesday, December 13, 2016 at 1:17:45 AM UTC+3, Nadine Sundquist 
> (AdWords API Team) wrote:
>>
>> Hello Burak,
>>
>> Usually when there is an error in the PHP library where the error is 
>> invalid_request, there's also an error_description. Can you see if that's 
>> available? It will usually tell you what field is causing the issue such as 
>> 'missing required parameter'. That may help us narrow this down.
>>
>> Thanks,
>> Nadine, AdWords API Team
>>
>> On Monday, December 12, 2016 at 7:51:03 AM UTC-5, Burak Karakan wrote:
>>>
>>> Hi Shwetha, any ideas on this? 
>>>
>>> We are unable to run our system for approximately 5 days, any help would 
>>> be amazing.
>>>
>>> Thanks again.
>>>
>>> On Saturday, December 10, 2016 at 11:41:45 AM UTC+3, Burak Karakan wrote:
>>>>
>>>> Hi Shwetha,
>>>>
>>>> We are building a web app, therefore the credentials are for a web app. 
>>>> I always create the credentials using the link you provided. In order to 
>>>> try the examples, I created installed type credentials as well in order to 
>>>> test the example files, but I could not make them work either, got the 
>>>> same 
>>>> error. 
>>>>
>>>> I created different clientID & secret couples but none of them worked. 
>>>> In the error stack, the error seems to be related to this call:
>>>>
>>>> at SimpleOAuth2Handler->MakeRequest('
>>>> https://accounts.google.com/o/oauth2/token', array('code' => 
>>>> 'my_auth_code_1234567', 'client_id' => '
>>>> my_client_id.apps.googleusercontent.com', 'client_secret' => 
>>>> 'my_client_secret', 'redirect_uri' => '
>>>> http://mydomain.com/auth/google/callback', 'grant_type' => 
>>>> 'authorization_code'))
>>>>
>>>> I don't know the working version of this call, therefore I don't know 
>>>> what is missing. I can try different things you advise.
>>>>
>>>> Thank you very much for your help.
>>>>
>>>> On Friday, December 9, 2016 at 9:36:27 PM UTC+3, Shwetha Vastrad 
>>>> (AdWords API Team) wrote:
>>>>>
>>>>> Hi Burak,
>>>>>
>>>>> Could you provide the steps you followed to create your OAuth2 
>>>>> credentials and generate the refresh token? Could you also let me know if 
>>>>> you are using Installed application type credentials or web app type 
>>>>> credentials? The invalid_request error usually occurs if a required 
>>>>> parameter is missing from the OAuth2 request. 
>>>>>
>>>>> Could you also try creating a new set of credentials by following the 
>>>>> instructions provided here 
>>>>> <https://developers.google.com/adwords/api/docs/guides/authentication#generate_oauth2_credentials>
>>>>>  and 
>>>>> let me know if it works? 
>>>>>
>>>>> Thanks,
>>>>> Shwetha, AdWords API Team.
>>>>>
>>>>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/9f4d5f0f-69e7-4571-a102-f60cb46432c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • PHP - Invalid ... Burak Karakan
    • Re: PHP -... 'Shwetha Vastrad (AdWords API Team)' via AdWords API Forum
      • Re: P... Burak Karakan
        • R... Burak Karakan
          • ... 'Nadine Sundquist (AdWords API Team)' via AdWords API Forum
            • ... Sabri Karagönen
            • ... Burak Karakan
            • ... Burak Karakan
              • ... 'Nadine Sundquist (AdWords API Team)' via AdWords API Forum

Reply via email to