2011-04-07 51 views
1

我試圖讓會話令牌使用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)) 
+0

你使用什麼認證機制?OAuth,AuthSub? – manji 2011-04-07 01:56:43

+0

AuthSub。我沒有看到OAuth機制。那樣比較容易嗎?一段時間以來,我使用OAuth作爲Twitter,並且我必須自己寫很多代碼。 Google是否更好? – Adam 2011-04-07 02:04:12

+1

谷歌推薦使用OAuth請看這裏:http://code.google.com/apis/gdata/docs/auth/oauth.html(在頁面底部) – manji 2011-04-07 02:11:31

回答

1

的文檔說:

NonAuthSubToken:若方法 來修改的AuthSub令牌用於 時 用戶要麼不認證,不爲 認證 通過另一種認證機制。

用戶通過身份驗證? (因爲您正在使用AuthSub而排除第二個原因)

另一方面,Google建議將OAuth與Google Data API一起使用。

請看這裏:OAuth 1.0 for Web Applications

+0

謝謝!這基本上意味着用戶需要登錄到Google(我是)還是這意味着我的RSA密鑰無效?我正在運行本地主機順便說一句。我沒有看到這是一個問題,因爲返回URL正在工作,但我想我會提到它。 – Adam 2011-04-07 02:44:12

+0

我得到了OAuth的工作,結果比我使用Twitter的OAuth的經驗少了很多痛苦。所以這絕對是個好消息。不知道AuthSub的問題是什麼,但我認爲它與在本地主機上運行有關,Google正試圖驗證我的域名。哦,OAuth工作。再次感謝! – Adam 2011-04-07 17:36:37

相關問題