kensentor
kensentor

Reputation: 453

Google Calendar Resource API

I have an existing Google Marketplace app that, when installed, makes a variety of calls to pull Google data on the user's behalf, and is working fine. It does use the Google Admin SDK, right now mostly the Directory API.

I'd like to start using the Google Calendar Resource API but am having trouble with it. Right now, my app mostly uses 2-legged OAuth1 (OAuth2 coming soon, hopefully). I've added the scope https://apps-apis.google.com/a/feeds/calendar/resource/ to my test application manifest. However, any call to get info ('https://apps-apis.google.com/a/feeds/calendar/resource/2.0/') fails with 'Unknown Authorization header'. Other calls using the same client class work fine, including the Directory API.

Does the Calendar Resource API not support 2-legged OAuth1 through the marketplace? I've tried the same scope and URL through the OAuth2 Playground and it works fine. I haven't been able to find the old OAuth1 Playground (decommissioned?)

Upvotes: 1

Views: 797

Answers (2)

FullStack
FullStack

Reputation: 6020

Looks like your headers do not contain the proper authorization. Here's what works for me using OAuth2:

  'Content-Type': 'application/atom+xml',
  'Authorization': 'Bearer ' + accessToken,
  'X-JavaScript-User-Agent': "Google APIs Explorer"

where accessToken is a variable storing the access token of an admin with API enabling rights, i.e. a superadmin

Upvotes: 0

Infinite Recursion
Infinite Recursion

Reputation: 6557

Solution by KRH from Revision 2:


The exact code is kind of hard to share since there's interconnected classes and so on, but here's basically what generates the client using the Ruby Signet Client library.

    oauth_args = {
      :authorization_uri => "https://www.google.com/accounts/OAuthAuthorizeToken",
      :token_credential_uri =>"https://www.google.com/accounts/OAuthGetAccessToken",
      :client_credential_key => config.google_marketplace_consumer_key
      :client_credential_secret => config.google_marketplace_consumer_secret
  }
  client = Signet::OAuth1::Client.new(oauth_args)
  client.two_legged = true
  client.requestor_id = owner.email
  client.get(:uri => 'https://apps-apis.google.com/a/feeds/calendar/resource/2.0/<test domain>')

Result returned:

Signet::AuthorizationError: Authorization failed.  Server message:
<HTML>
<HEAD>
<TITLE>Unknown authorization header</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unknown authorization header</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

Note that I can take this exact same generation code and call the Directory API, and get a result.

Upvotes: 1

Related Questions