gkhngcmn / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
0 stars 0 forks source link

Required parameter is missing: grant_type #73

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run the calendar sample
2. Click connect and give approval
3. Redirect to to app

What is the expected output? What do you see instead?
When the redir uri is opened a 'apiAuthException' is thrown with the following 
message: "Required parameter is missing: grant_type"

What version of the product are you using? On what operating system?
0.4.8.3

Please provide any additional information below.
I am using the global config to setup everything except for the redir uri.

Original issue reported on code.google.com by ivandt...@gmail.com on 20 Jan 2012 at 4:35

GoogleCodeExporter commented 8 years ago
Hey ivanndoit, can you try the latest version available on trunk, and see if 
that fixes the issue?

http://code.google.com/p/google-api-php-client/source/checkout

Thank you,
Chirag

Original comment by chirags@google.com on 1 Feb 2012 at 8:03

GoogleCodeExporter commented 8 years ago
Hi Chirag, Thanks for responding.

I tried the current revision, but it gave me the same error.
I did change 2 things before running the example:
1) Added my developer info to the config file.
2) Changed CURLOPT_SSL_VERIFYPEER to FALSE in the apiCurlIO.php file (It gives 
me a ssl verification error otherwise.)

Original comment by ivandt...@gmail.com on 2 Feb 2012 at 3:57

GoogleCodeExporter commented 8 years ago
I did some testing and the post body of the CURL request does have a grant_type 
with a value in the array as it is set in the curl options. So either the curl 
request is not sending it or the api does not see it.

Original comment by ivandt...@gmail.com on 2 Feb 2012 at 4:06

GoogleCodeExporter commented 8 years ago
Which version of libcurl/php are you using? This should help me reproduce the 
issue.

Original comment by chirags@google.com on 3 Feb 2012 at 8:13

GoogleCodeExporter commented 8 years ago
I am using php 5.3.1 on Windows with Apache as my server.

This is the curl section of php info:
cURL support    enabled
cURL Information    7.19.6
Age 3
Features
AsynchDNS   No
Debug   No
GSS-Negotiate   No
IDN Yes
IPv6    No
Largefile   Yes
NTLM    Yes
SPNEGO  No
SSL Yes
SSPI    No
krb4    No
libz    Yes
CharConv    No
Protocols   tftp, ftp, telnet, dict, ldap, ldaps, http, file, https, ftps
Host    i686-pc-mingw32
SSL Version OpenSSL/0.9.8l
ZLib Version    1.2.3

Original comment by ivandt...@gmail.com on 4 Feb 2012 at 3:12

GoogleCodeExporter commented 8 years ago
hi dude,
 i also getting same issue

Fatal error: Uncaught exception 'apiAuthException' with message 'Error fetching 
OAuth2 access token, message: '<HTML> <HEAD> <TITLE>Required parameter is 
missing: grant_type</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> 
<H1>Required parameter is missing: grant_type</H1> <H2>Error 400</H2> </BODY> 
</HTML> '' in 
C:\xampp\htdocs\gfp\google-api-php-client\src\auth\apiOAuth2.php:104 Stack 
trace: #0 C:\xampp\htdocs\gfp\google-api-php-client\src\apiClient.php(131): 
apiOAuth2->authenticate(Array) #1 
C:\xampp\htdocs\gfp\google-api-php-client\examples\calendar\simple.php(21): 
apiClient->authenticate() #2 {main} thrown in 
C:\xampp\htdocs\gfp\google-api-php-client\src\auth\apiOAuth2.php on line 104

Original comment by smb.ma...@gmail.com on 5 Feb 2012 at 2:04

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi,

I have same error: 

Fatal error: Uncaught exception 'apiAuthException' with message 'Error fetching 
OAuth2 access token, message: '<HTML>
<HEAD>
<TITLE>Required parameter is missing: grant_type</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Required parameter is missing: grant_type</H1>
<H2>Error 400</H2>
</BODY>
</HTML>
'' in /www/sites/5/site10085/public_html/dp/google-api/auth/apiOAuth2.php:104
Stack trace:
#0 /www/sites/5/site10085/public_html/dp/google-api/apiClient.php(131): 
apiOAuth2->authenticate(Array)
#1 /www/sites/5/site10085/public_html/dp/index.php(36): 
apiClient->authenticate()
#2 {main}
  thrown in /www/sites/5/site10085/public_html/dp/google-api/auth/apiOAuth2.php on line 104

My only edit to code was

$client->setClientId('##################');
$client->setClientSecret('##################');
$client->setRedirectUri('##################');
$client->setDeveloperKey('##################');

and I changed CURLOPT_SSL_VERIFYPEER to FALSE in the apiCurlIO.php file.

I have same error on server (www.php5.sk) but in localhost(XAMPP 1.7.7 win32) 
it is working perfect.

Anyone have solution yet?

PS: I do change $client for localhost. Have API for localhost and php5.sk server

Original comment by ing.mich...@gmail.com on 7 Feb 2012 at 3:51

GoogleCodeExporter commented 8 years ago
Hey everybody,

This should really be fixed in 0.4.9. Please let me know if it doesn't fix the 
issue!
Link: 
http://code.google.com/p/google-api-php-client/downloads/detail?name=google-api-
php-client-0.4.9.tar.gz

Original comment by chirags@google.com on 9 Feb 2012 at 7:09

GoogleCodeExporter commented 8 years ago

Original comment by chirags@google.com on 9 Feb 2012 at 9:58

GoogleCodeExporter commented 8 years ago
Hey Chirags, 

I am sad to report that the changes did not resolve the issue.

Original comment by ivandt...@gmail.com on 10 Feb 2012 at 12:17

GoogleCodeExporter commented 8 years ago
Hmm, I apparently fixed an unrelated bug then. I need some more information 
then. 

Can you add the following line inside io/apiCurlIO.php right above line 112 
(above curl_exec):
curl_setopt($ch, CURLOPT_VERBOSE, 1);

And then send me the request/response that's logged (make sure you strip out 
any tokens included within the request)

Original comment by chirags@google.com on 10 Feb 2012 at 12:22

GoogleCodeExporter commented 8 years ago
This is what I get from the Apache error log:

* About to connect() to accounts.google.com port 443 (#0)
*   Trying 173.194.67.84... * connected
* Connected to accounts.google.com (173.194.67.84) port 443 (#0)
* SSL connection using RC4-SHA
* Server certificate:
*    subject: C=US; ST=California; L=Mountain View; O=Google Inc; 
CN=accounts.google.com
*    start date: 2011-07-21 00:00:00 GMT
*    expire date: 2013-07-18 23:59:59 GMT
*    common name: accounts.google.com (matched)
*    issuer: C=ZA; O=Thawte Consulting (Pty) Ltd.; CN=Thawte SGC CA
*    SSL certificate verify result: unable to get local issuer certificate (20), 
continuing anyway.
> POST /o/oauth2/token HTTP/1.1
User-Agent: Google Calendar PHP Starter Application google-api-php-client/0.4.8
Host: accounts.google.com
Accept: */*
content-type: application/x-www-form-urlencoded
content-length: 245

< HTTP/1.1 400 Required parameter is missing: grant_type
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: Fri, 01 Jan 1990 00:00:00 GMT
< Date: Fri, 10 Feb 2012 17:16:23 GMT
< Content-Type: text/html; charset=UTF-8
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Transfer-Encoding: chunked
< 
* Connection #0 to host accounts.google.com left intact
* Closing connection #0

There is nothing else, no post body or nothing. I did not event strip out any 
tokens.

Original comment by ivandt...@gmail.com on 10 Feb 2012 at 5:38

GoogleCodeExporter commented 8 years ago
Thanks for that! I'm still trying to place where the issue is.

Can add add this line before processEntityRequest()
    error_log("Before process entity: " . print_r($request->getPostBody(), true));

Also, add this line before the curl exec (you can remove the curlopt_verbose 
line)
    error_log("Before curl_exec: " . print_r($request->getPostBody(), true));

Thank you so much for helping debug this!

Original comment by chirags@google.com on 10 Feb 2012 at 6:15

GoogleCodeExporter commented 8 years ago
This is the result (Censored some of the data):

[Fri Feb 10 21:00:27 2012] [error] [client 127.0.0.1] Before process entity: 
Array\n(\n    [code] => 4/bH_B78RcQOOyHS6AAGskRB52****\n    [grant_type] => 
authorization_code\n    [redirect_uri] => 
http://me/google/examples/calendar/simple.php\n    [client_id] => 
***294485334.apps.googleusercontent.com\n    [client_secret] => ******\n)\n
[Fri Feb 10 21:00:27 2012] [error] [client 127.0.0.1] Before curl_exec: 
code=4%2FbH_B78RcQOOyHS6AAGskRB52jySS&grant_type=authorization_code&redirect_uri
=http%3A%2F%2Fme%2Fgoogle%2Fexamples%2Fcalendar%2Fsimple.php&client_id=***294485
334.apps.googleusercontent.com&client_secret=*****

Original comment by ivandt...@gmail.com on 10 Feb 2012 at 7:03

GoogleCodeExporter commented 8 years ago
Wow thank you so much! You can remove those debug statements now.

The bug is with http_build_query using "&" instead of "&" on certain builds of 
PHP (according to the comments on 
http://php.net/manual/en/function.http-build-query.php)

A quick fix is to change the line:
      $postBody = http_build_query($postBody);

to:
      $postBody = http_build_query($postBody, '', '&');

I'm working on spinning off a new build to fix this issue, but can you confirm 
that this finally fixes the issue :)

Original comment by chirags@google.com on 10 Feb 2012 at 7:19

GoogleCodeExporter commented 8 years ago
Ok cool that fixed it. Thanks for sticking with it on this issue.

Original comment by ivandt...@gmail.com on 10 Feb 2012 at 7:49

GoogleCodeExporter commented 8 years ago

Original comment by chirags@google.com on 10 Feb 2012 at 7:50