我試圖讓會話令牌使用Google Calendar API使用Python庫。我使用的是Django 1.2.1和Python 2.7。該頁面基本上有一個「登錄Google日曆」(請參閱下面的auth_url變量)鏈接,該鏈接請求單次使用令牌。從我所能告訴的單個使用標記看起來完全如我所期望的那樣(讀取:沒有來自Google的錯誤消息)。但是當我升級到會話令牌時,我得到一個NonAuthSubToken錯誤。有任何想法嗎?這裏是我的代碼嘗試使用Python獲取Google日曆的會話標記。獲取NonAuthSubToken錯誤
def get_auth_url():
next = SITE_DOMAIN + '/job/events'
scope = 'https://www.google.com/calendar/feeds/'
secure = True
session = True
calendar_service = gdata.calendar.service.CalendarService()
return calendar_service.GenerateAuthSubURL(next, scope, secure, session)
@login_required
def get_events(request):
auth_url = get_auth_url()
if 'token' in request.GET:
f = open('rsa.pem')
rsa_key = f.read()
f.close()
single_use_token = gdata.auth.extract_auth_sub_token_from_url(SITE_DOMAIN + request.get_full_path(), rsa_key=rsa_key)
calendar_service = gdata.calendar.service.CalendarService()
calendar_service.auth_token = str(single_use_token)
calendar_service.UpgradeToSessionToken()
return render_to_response('getevents.html', {'useremail': request.user.email.replace('@', '%40'),'auth_url': auth_url}, context_instance=RequestContext(request))
你使用什麼認證機制?OAuth,AuthSub? – manji 2011-04-07 01:56:43
AuthSub。我沒有看到OAuth機制。那樣比較容易嗎?一段時間以來,我使用OAuth作爲Twitter,並且我必須自己寫很多代碼。 Google是否更好? – Adam 2011-04-07 02:04:12
谷歌推薦使用OAuth請看這裏:http://code.google.com/apis/gdata/docs/auth/oauth.html(在頁面底部) – manji 2011-04-07 02:11:31