Authorized token from Service Provider does not match supplied Request Token details

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Authorized token from Service Provider does not match supplied Request Token details

maykino
This post was updated on .
HI everyone! I followed the tutorial: http://code.google.com/apis/gdata/docs/auth/oauth.html#OAuthRequestToken

and I built the following code:

<?
session_start();
ini_set("display_errors", 1);
require_once 'Zend/Loader.php';
require_once 'Zend/Oauth/Consumer.php';
$CONSUMER_KEY = '1212121.apps.googleusercontent.com';
$CONSUMER_SECRET = 'gVdWZAMrxi121212QSz9Zj';
$BASE_URL = 'http://www.xxx.com/helloworld';
$STORE_PATH = "/tmp/_php_consumer_test";
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
Zend_Loader::loadClass('Zend_Gdata_Query');
$SCOPES = array(
  'https://www.google.com/m8/feeds/'
);
$options = array(
    'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
    'version' => '1.0',
    'signatureMethod' => 'HMAC-SHA1',
    'consumerKey' => $CONSUMER_KEY,
    'consumerSecret' => $CONSUMER_SECRET,
        'callbackUrl' => 'http://www.stingerit.com/helloworld/test.php',
        'requestTokenUrl' => '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($options);
if (!isset($_SESSION['ACCESS_TOKEN'])) {
         $_SESSION['REQUEST_TOKEN'] = serialize($consumer->getRequestToken(array('scope' => implode(' ', $SCOPES))));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$approvalUrl = $consumer->getRedirectUrl(array('hd' => 'default'));
echo "<a href=\"$approvalUrl\">Grant access";
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        if (!isset($_SESSION['ACCESS_TOKEN'])) {
          if (!empty($_GET) && isset($_SESSION['REQUEST_TOKEN'])) {
                $_SESSION['ACCESS_TOKEN'] = serialize($consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN'])));
          }
        }
        if (isset($_SESSION['ACCESS_TOKEN'])) {
          $accessToken = unserialize($_SESSION['ACCESS_TOKEN']);
        } else {
          exit;
        }
$httpClient = $accessToken->getHttpClient($options);
$client = new Zend_Gdata($httpClient);
$query = new Zend_Gdata_Query("http://www.google.com/m8/feeds/contacts/default/full");
$feed = $client->getFeed($query);
foreach ($feed->entries as $entry) {
  echo "$entry->title\n";
}
?>



However, it throws an error saying:

Grant access
Fatal error: Uncaught exception 'Zend_Oauth_Exception' with message 'Authorized token from Service Provider does not match supplied Request Token details' in /home/stingeri/public_html/helloworld/Zend/Oauth/Consumer.php:208 Stack trace: #0 /home/stingeri/public_html/helloworld/test.php(38): Zend_Oauth_Consumer->getAccessToken(Array, Object(Zend_Oauth_Token_Request)) #1 {main} thrown in /home/stingeri/public_html/helloworld/Zend/Oauth/Consumer.php on line 208

So it looks like I'm providing wrong tokens. Can you please tell me what I do wrong?

Regards
M.
Reply | Threaded
Open this post in threaded view
|

Re: Authorized token from Service Provider does not match supplied Request Token details

Ryan Boyd-3
Where did you get that consumer key?  That looks like the style of consumer
key we issue for OAuth 2.0-- whereas for OAUth 1.0, you need to register
using the instructions on this page:
http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html

The reg URL for OAuth 1.0 is here:
https://www.google.com/accounts/ManageDomains



On Wed, Jun 29, 2011 at 2:02 AM, maykino <[hidden email]> wrote:

> HI everyone! I managed the tutorial:
> http://code.google.com/apis/gdata/docs/auth/oauth.html#OAuthRequestToken
>
> and I build the following code:
>
> <?
> session_start();
> ini_set("display_errors", 1);
> require_once 'Zend/Loader.php';
> require_once 'Zend/Oauth/Consumer.php';
> $CONSUMER_KEY = '1212121.apps.googleusercontent.com';
> $CONSUMER_SECRET = 'gVdWZAMrxi121212QSz9Zj';
> $BASE_URL = 'http://www.xxx.com/helloworld';
> $STORE_PATH = "/tmp/_php_consumer_test";
> Zend_Loader::loadClass('Zend_Gdata');
> Zend_Loader::loadClass('Zend_Gdata_Gapps');
> Zend_Loader::loadClass('Zend_Gdata_Query');
> $SCOPES = array(
>  'https://www.google.com/m8/feeds/'
> );
> $options = array(
>    'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
>    'version' => '1.0',
>    'signatureMethod' => 'HMAC-SHA1',
>    'consumerKey' => $CONSUMER_KEY,
>    'consumerSecret' => $CONSUMER_SECRET,
>        'callbackUrl' => 'http://www.stingerit.com/helloworld/test.php',
>        'requestTokenUrl' =>
> '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($options);
> if (!isset($_SESSION['ACCESS_TOKEN'])) {
>         $_SESSION['REQUEST_TOKEN'] =
> serialize($consumer->getRequestToken(array('scope' => implode(' ',
> $SCOPES))));
> }
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> $approvalUrl = $consumer->getRedirectUrl(array('hd' => 'default'));
> echo " \"$approvalUrl\" Grant access ";
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>        if (!isset($_SESSION['ACCESS_TOKEN'])) {
>          if (!empty($_GET) && isset($_SESSION['REQUEST_TOKEN'])) {
>                $_SESSION['ACCESS_TOKEN'] =
> serialize($consumer->getAccessToken($_GET,
> unserialize($_SESSION['REQUEST_TOKEN'])));
>          }
>        }
>        if (isset($_SESSION['ACCESS_TOKEN'])) {
>          $accessToken = unserialize($_SESSION['ACCESS_TOKEN']);
>        } else {
>          exit;
>        }
> $httpClient = $accessToken->getHttpClient($options);
> $client = new Zend_Gdata($httpClient);
> $query = new
> Zend_Gdata_Query("http://www.google.com/m8/feeds/contacts/default/full");
> $feed = $client->getFeed($query);
> foreach ($feed->entries as $entry) {
>  echo "$entry->title\n";
> }
> ?>
>
>
>
> However, it throws an error saying:
>
> Grant access
> Fatal error: Uncaught exception 'Zend_Oauth_Exception' with message
> 'Authorized token from Service Provider does not match supplied Request
> Token details' in
> /home/stingeri/public_html/helloworld/Zend/Oauth/Consumer.php:208 Stack
> trace: #0 /home/stingeri/public_html/helloworld/test.php(38):
> Zend_Oauth_Consumer->getAccessToken(Array,
> Object(Zend_Oauth_Token_Request))
> #1 {main} thrown in
> /home/stingeri/public_html/helloworld/Zend/Oauth/Consumer.php on line 208
>
> So it looks like I'm providing wrong tokens. Can you please tell me what I
> do wrong?
>
> Regards
> M.
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/Authorized-token-from-Service-Provider-does-not-match-supplied-Request-Token-details-tp3631388p3631388.html
> Sent from the Zend gdata mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Authorized token from Service Provider does not match supplied Request Token details

maykino
Thank you for your response. You were right, I was using the consumer key  that I got from Google Marketplace. I changed it to the correct one and it seems like I'm one step closer.. The following code throws an error:

ERROR:Expected response code 200, got 401
Authorization required
Error 401

However, when I change to last few lines to work with Google Docs it works perfectly. It looks like I'm doing something wrong with my code for Contacts API. Take a look:

test.php

<?
session_start();
ini_set("display_errors", 1);
require_once 'Zend/Loader.php';
require_once 'Zend/Oauth/Consumer.php';
$CONSUMER_KEY = 'www.stingerit.com';
$CONSUMER_SECRET = 'WHymWg9mjRlRNsA4Uhxxxxxx';
$BASE_URL = 'http://www.stingerit.com/helloworld';
$STORE_PATH = "/tmp/_php_consumer_test";
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
Zend_Loader::loadClass('Zend_Gdata_Query');
$SCOPES = array(
  'https://www.google.com/m8/feeds',
  'https://docs.google.com/feeds/',
  'https://spreadsheets.google.com/feeds/'
);

$options = array(
    'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
    'version' => '1.0',
    'signatureMethod' => 'HMAC-SHA1',
    'consumerKey' => $CONSUMER_KEY,
    'consumerSecret' => $CONSUMER_SECRET,
        'callbackUrl' => 'http://www.stingerit.com/helloworld/test1.php',
        'requestTokenUrl' => '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($options);
if (!isset($_SESSION['ACCESS_TOKEN'])) {
         $_SESSION['REQUEST_TOKEN'] = serialize($consumer->getRequestToken(array('scope' => implode(' ', $SCOPES))));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$approvalUrl = $consumer->getRedirectUrl(array('hd' => 'default'));
echo "<a href=\"$approvalUrl\">Grant access";
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


?>


test1.php

<?
require_once 'Zend/Oauth/Consumer.php';
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Feed');
session_start();
global $_SESSION;
$CONSUMER_KEY = 'www.stingerit.com';
$CONSUMER_SECRET = 'WHymWg9mjRlRNsA4UhBWo67f';
// Multi-scoped token.
$SCOPES = array(
  'https://www.google.com/m8/feeds',
  '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://www.stingerit.com/helloworld/test1.php',
  'requestTokenUrl' => '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 (!isset($_SESSION['ACCESS_TOKEN'])) {echo "in first if /br";
  if (!empty($_GET) && isset($_SESSION['REQUEST_TOKEN'])) { echo "gotm";
    $_SESSION['ACCESS_TOKEN'] = serialize($consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN'])));
  }
}

if (isset($_SESSION['ACCESS_TOKEN'])) {
        $accessToken = unserialize($_SESSION['ACCESS_TOKEN']);
}else {
        exit;
}

$httpClient = $accessToken->getHttpClient($oauthOptions);
//$client = new Zend_Gdata_Docs($httpClient, "yourCompany-YourAppName-v1");
// Retrieve user's list of Google Docs
//$feed = $client->getDocumentListFeed();
try {
        $gdata = new Zend_Gdata($client);
        $gdata->setMajorProtocolVersion(3);
        $query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full');
        $feed = $gdata->getFeed($query);
// foreach ($feed->entries as $entry) {
// echo "$entry->title\n";
// }
} catch (Exception $e) {
    die('ERROR:' . $e->getMessage());  
}
?>


You can find this example here:

http://www.stingerit.com/helloworld/test1.php

Why do I get this error?