"Unknown authorization header" whle fetching google contacts using php, (zend) gdata and 2 legged OAuth

715 views
Skip to first unread message

Amit

unread,
Sep 21, 2011, 2:43:18 AM9/21/11
to google-co...@googlegroups.com

I am writing a 2 Legged OAuth app for Google Apps (Google Marketplace app) using zend gdata PHP client library.

I get "Unknown authorization header" when I execute following code to fetch google contacts.

Code as given below.

require_once 'Zend/Oauth/Consumer.php';
$oauthOptions = array(
    'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
    'version' => '1.0',
    'signatureMethod' => 'HMAC-SHA1',
    'consumerKey' => $CONSUMER_KEY,
    'consumerSecret' => $CONSUMER_SECRET
);

$consumer = new Zend_Oauth_Consumer($oauthOptions);
$token = new Zend_Oauth_Token_Access();
$httpClient = $token->getHttpClient($oauthOptions);

$url = 'http://www.google.com/m8/feeds/contacts/default/full';

require_once 'Zend/Gdata/Gapps.php';
$gdata = new Zend_Gdata($httpClient);

require_once 'Zend/Gdata/Query.php';
require_once 'Zend/Gdata/Feed.php';
require_once 'Zend/Gdata/App.php';

$query = new Zend_Gdata_Query($url);
try {
    $feed = $gdata->getFeed($query);
} catch(Zend_Gdata_App_Exception $ex){
    print_r($ex->getMessage());
}

Error:

Expected response code 200, got 401
Unknown authorization header
Error 401


Please let me know what am I missing here.

Amit

unread,
Sep 21, 2011, 2:48:12 AM9/21/11
to google-co...@googlegroups.com
Additionally, the HTTP headers sent on executing above code are:

GET /m8/feeds/contacts/default/full HTTP/1.1
Host: www.google.com
Connection: close
User-Agent: MyCompany-MyApp-1.0 Zend_Framework_Gdata/1.11.0dev
Accept-encoding: identity
Authorization: OAuth realm="",oauth_consumer_key="686518909188.apps.googleusercontent.com",oauth_nonce="fc99e10f42cdb01c7f3ce1ab2775e616",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1316583946",oauth_version="1.0",oauth_signature="hlbTvPExy4r4%2FyY1ddEsy1AJhf4%3D"


HTTP Response received:

HTTP/1.1 401 Unknown authorization header
Content-Type: text/html; charset=UTF-8
Date: Wed, 21 Sep 2011 05:45:47 GMT
Expires: Wed, 21 Sep 2011 05:45:47 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Connection: close

<HTML>
<HEAD>
<TITLE>Unknown authorization header</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unknown authorization header</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

Geraldo Magella Junior

unread,
Sep 21, 2011, 8:12:00 AM9/21/11
to google-co...@googlegroups.com
Hi Amit,
I didn't saw the requestor ID. If you're using 2LO you have to inform whic user you want to retrieve informations for:
it should be something like this:

'http://www.google.com/m8/feeds/contacts/default/full?xoauth_requestor_id=**USER*EMAIL**

[]'s
Geraldo Magella Junior Valadares



--
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
google-co...@googlegroups.com
To unsubscribe from this group, send email to
google-contacts...@googlegroups.com
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html

Amit

unread,
Sep 21, 2011, 8:52:21 AM9/21/11
to google-co...@googlegroups.com
Hi Geraldo,
I have set "xoauth_requestor_id" in query string. But now I get error regarding "Token invalid - AuthSub token has wrong scope" I am posting http headers below:

HTTP Request:

GET /m8/feeds/contacts/default/full/?xoauth_requestor_id=testaccamit%40test.issueburner.com HTTP/1.1
Connection: close
User-Agent: MyCompany-MyApp-1.0 Zend_Framework_Gdata/1.11.0dev
Accept-encoding: identity
Authorization: OAuth realm="",oauth_consumer_key="686518909188.apps.googleusercontent.com",oauth_nonce="0bc13a9de282e7e3fbe431be241e53b6",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1316609206",oauth_version="1.0",oauth_signature="yp6aA0cbQh4ihpcKVK1DadRuu%2F4%3D"



HTTP Response:

HTTP/1.1 401 Token invalid - AuthSub token has wrong scope
Content-Type: text/html; charset=UTF-8
Date: Wed, 21 Sep 2011 12:46:47 GMT
Expires: Wed, 21 Sep 2011 12:46:47 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Connection: close

<HTML>
<HEAD>
<TITLE>Token invalid - AuthSub token has wrong scope</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid - AuthSub token has wrong scope</H1>

Geraldo Magella Junior

unread,
Sep 21, 2011, 9:42:44 AM9/21/11
to google-co...@googlegroups.com
You have to check if your application XML (manifest) includes this scope (/m8/feeds/contacts) Can you post it?

[]'s
Geraldo Magella Junior Valadares


--

Gaurav Tomer

unread,
Oct 1, 2011, 6:19:06 PM10/1/11
to google-co...@googlegroups.com
yes sir , the scope is included in the manifiest but still there is same problem


  <Extension >
   <Scope ref="contactsFeed"/>
 </Extension>

<!-- Authorized Data access -->
    <Scope id="contactsFeed">
       <Reason>contacts</Reason>
    </Scope>
.
.
</ApplicationManifest>

Gaurav Tomer

unread,
Oct 2, 2011, 7:56:16 AM10/2/11
to google-co...@googlegroups.com
now its working .... thanks

Oscar Rodriguez

unread,
Apr 20, 2012, 6:33:30 PM4/20/12
to google-co...@googlegroups.com
I'm having the same problem. How did you finally fix it?

Gaurav Tomer <admin <at> dancexd.com> writes:

>
>
> now its working .... thanks
>
>
>
>


Ryan Schumacher

unread,
May 18, 2012, 3:39:32 PM5/18/12
to google-co...@googlegroups.com
When I experienced this issue I forgot to add: ?xoauth_requestor_id=em...@address.com

Ex. using the code above:

require_once 'Zend/Oauth/Consumer.php';
$oauthOptions = array(
    'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
    'version' => '1.0',
    'signatureMethod' => 'HMAC-SHA1',
    'consumerKey' => $CONSUMER_KEY,
    'consumerSecret' => $CONSUMER_SECRET
);

$consumer = new Zend_Oauth_Consumer($oauthOptions);
$token = new Zend_Oauth_Token_Access();
$httpClient = $token->getHttpClient($oauthOptions);


require_once 'Zend/Gdata/Gapps.php';
$gdata = new Zend_Gdata($httpClient);

require_once 'Zend/Gdata/Query.php';
require_once 'Zend/Gdata/Feed.php';
require_once 'Zend/Gdata/App.php';

$query = new Zend_Gdata_Query($url);
// Add requestor 
$zend_query->setParam('xoauth_requestor_id', 'em...@address.com');
 
try {
    $feed = $gdata->getFeed($query);
} catch(Zend_Gdata_App_Exception $ex){
    print_r($ex->getMessage());
}

Reply all
Reply to author
Forward
0 new messages