Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6789681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:38:01+00:00 2026-05-26T17:38:01+00:00

I am writing a 2 Legged OAuth app (Google Marketplace app) using zend gdata

  • 0

I am writing a 2 Legged OAuth app (Google Marketplace app) using zend gdata library.
I need 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());
}

I get following error:

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

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>

Please let me know what am I missing here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:38:01+00:00Added an answer on May 26, 2026 at 5:38 pm

    It appears that the “xoauth_requestor_id” request parameter is not being set when using 2-legged OAuth (xoauth).

    I tried setting this query parameter on the HttpClient object that is passed to the Zend_Gdata_Calendar constructor:

    $httpClient->setParameterGet('xoauth_requestor_id', $userEmail);
    

    But unfortunately this clean approach didn’t work. Seems that the Zend_GData_Calendar class isn’t fully utilising the injected HttpClient object.

    So I’ve resorted to extending Zend_GData_Calendar and instantiating my customised version of it instead. I’ve not fully tested all the functionality but here is what I have so far and it can easily be built upon:

    /**
     * Slightly modified class which extends Zend_Gdata_Calendar. Fixes a problem with the request URI when using 2-legged
     * OAuth (xoauth). Adds on the xoauth_requestor_id query parameter.
     */
    class Xoauth_Gdata_Calendar extends Zend_Gdata_Calendar {
        protected $requestorId;
    
        /**
         * Set the xoauth_requestor_id for requests
         *
         * @param string $requestorId
         */
        public function setRequestorId($requestorId) {
            $this->requestorId = $requestorId;
        }
    
        /**
         * Get the currently set xoauth_requestor_id
         *
         * @return string
         */
        public function getRequestorId() {
            return $this->requestorId;
        }
    
        /**
         * {@inheritdoc} extended to also include the xoauth_requestor_id query parameter in the request URI. This fixes
         * an authentication issue when using 2-legged OAuth (xoauth).
         *
         * @return string|Zend_Gdata_App_Feed
         */
        public function getCalendarListFeed() {
            $uri = self::CALENDAR_FEED_URI . '/default';
            if($this->requestorId) {
                $uri .= '?xoauth_requestor_id=' . urlencode($this->requestorId);
            }
    
            return parent::getFeed($uri,'Zend_Gdata_Calendar_ListFeed');
        }
    }
    

    Then to use this you instantiate this class rather Zend_Gdata_Calendar base class. You just need to call setRequestorId($usersEmail), for example:

    $calendarClient = new Xoauth_Gdata_Calendar($httpClient);
    $calendarClient->setRequestorId($userEmail);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I am currently writing an web application where you need to log in, using
I'm looking for a tutorial/example/explanation about writing a two-legged provider for OAuth in Django.
I'm writing a little single page app (using knockout.js :-)) whereby i have a
Writing the code for the user authentication portion of a web site (including account
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing documentation in html requires some code examples. What to do with characters that
Writing a python program, and I came up with this error while using the
Writing an asynchronous Ping using Raw Sockets in F#, to enable parallel requests using
I am writing an app that requires you to be logged in to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.