Hello world!
I'm creating a django app that creates a calendar and a google docs folder for the users, and uses the API to insert events and add documents. A few months ago, it worked nice enough; now I'm doing a major refactoring of my code and, while testing the aforementioned components, I discovered that they don't work anymore! When I try to create a folder or a calendar, i get this response from the API:
RequestError: {'status': 401, 'body': '<HTML>\n<HEAD>\n<TITLE>Unknown authorization header</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Unknown authorization header</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n', 'reason': 'Unknown authorization header'}
My code looks like this -based on this example in the google documentation- (the docs code is shorter, so I'll paste that one, though the authentication bit is actually a function common to both):
from gdata.auth import OAuthSignatureMethod, OAuthToken, OAuthInputParams
from gdata.calendar.service import CalendarService
from django.conf import settings
client_instance = CalendarService()
client_instance.SetOAuthInputParameters(OAuthSignatureMethod.HMAC_SHA1,
settings.OAUTH_CONSUMER_KEY,
consumer_secret=settings.OAUTH_CONSUMER_SECRET)
user_tokens = UserToken.objects.get(user=user)
if not user_tokens.oauth_access_token_value or not user_tokens.oauth_valid_token:
raise Exception('The user has not allowed us to access his services')
oauth_token=OAuthToken(key=user_tokens.oauth_access_token_value, secret=user_tokens.oauth_access_token_secret)
oauth_token.oauth_input_params = OAuthInputParams(OAuthSignatureMethod.HMAC_SHA1,
settings.OAUTH_CONSUMER_KEY,
consumer_secret=settings.OAUTH_CONSUMER_SECRET)
client_instance.SetOAuthToken(oauth_token)
new_folder = docs_service.CreateFolder("some folder")
The exception comes from that last line, has something changed in the API or it's just me? (I bet it's just me, but I can't see it since it worked a couple of months ago)