Zend Oauth with Google?

110 views
Skip to first unread message

xhe

unread,
Mar 5, 2011, 12:36:33 AM3/5/11
to Zend Framework Developers
I want to use zend_oauth to enable use to login through their google
account, and then retrieve their personal information to populate into
my app. I have successfully used zend_oauth with twitter/linkedIn, but
when using with google, always failed! This is what I wrote:

$CONSUMER_KEY = "www.xxxx.com";
$CONSUMER_SECRET = "eFguvfqNKZZVVwJD8khBbywb ";


// Multi-scoped token.
$SCOPES = array(
'https://docs.google.com/feeds/',
'https://spreadsheets.google.com/feeds/'
);

$oauthOptions = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '1.0',
'consumerKey' => $CONSUMER_KEY,
'consumerSecret' => $CONSUMER_SECRET,
'signatureMethod' => 'HMAC-SHA1',
'callbackUrl' => 'http://xxxx.com',
'requestTokenUrl' => 'https://www.google.com/accounts/
OAuthGetRequestToken',
'siteUrl' => 'https://www.google.com/accounts/
OAuthGetRequestToken',
'userAuthorizationUrl' => 'https://www.google.com/accounts/
OAuthAuthorizeToken',
'accessTokenUrl' => 'https://www.google.com/accounts/
OAuthGetAccessToken'
);

$consumer = new Zend_Oauth_Consumer($oauthOptions);


if(! ($this->getUser()->hasAttribute("ACCESS_TOKEN_GOOGLE")))
{

if (! empty ( $_GET )) {

$token = $consumer->getAccessToken ( $_GET,
unserialize ( $this->getUser()-
>getAttribute("REQUEST_TOKEN_GOOGLE")));

$this->getUser()-
>setAttribute("ACCESS_TOKEN_GOOGLE",$token);


} else {

$token = $consumer->getRequestToken
( array('scope' => implode(' ', $SCOPES)) );

$this->getUser()-
>setAttribute("REQUEST_TOKEN_GOOGLE",serialize ( $token ));

$consumer->redirect ();

}

} else {

$token = unserialize ($socialSession-
>ACCESS_TOKEN_GOOGLE);

}


Session management here is using symfony as my site was written in
symfony, so I just used zend library.

whenever I run, I always got error:

500 | Internal Server Error | Zend_Oauth_Exception
Could not retrieve a valid Token response from Token URL:
signature_invalid
base_string:POST&https%3A%2F%2Fwww.google.com%2Faccounts
%2FOAuthGetRequestToken&oauth_callback%3Dhttp%2...

Can anyone post a simple working code and tell me why I am always
wrong here?

Thanks
Reply all
Reply to author
Forward
0 new messages