2011-08-15 33 views
0

我正在構建一個應用程序,該應用程序使用Python gdata庫訪問Google Contacts,並且需要通過該庫進行身份驗證才能使我的請求正常工作。我對此很陌生,但基本上我正在構建一個服務,該服務運行在cron作業上,以便從Google獲取聯繫人以將其備份到本地數據庫。如何使用Google爲Google Contacts API驗證我的Python應用程序?

如何在gdata.contacts.client.ContactsClient對象上運行get_contacts()之前觸發身份驗證?有沒有一種方法可以顯示WebKit瀏覽器或使用默認瀏覽器來驗證應用程序?除了身份驗證之外,它將是一個將在後臺運行的命令行應用程序。我該怎麼做呢?

回答

1

這是用於Google文檔,但我認爲實踐是一樣的嗎?

import gdata.docs.service 

# Create a client class which will make HTTP requests with Google Docs server. 
client = gdata.docs.service.DocsService() 
# Authenticate using your Google Docs email address and password. 
client.ClientLogin('[email protected]', 'password') 

# Query the server for an Atom feed containing a list of your documents. 
documents_feed = client.GetDocumentListFeed() 
# Loop through the feed and extract each document entry. 
for document_entry in documents_feed.entry: 
    # Display the title of the document on the command line. 
    print document_entry.title.text 

更多信息:http://code.google.com/apis/gdata/articles/python_client_lib.html

+0

我將如何顯示在瀏覽器窗口,所以我不能夠收集密碼,但得到的OAuth令牌呢? –

+0

啊,我看到你現在說的話(有時候我快速瀏覽:D)。我不是100%確定如何解決你的問題,但你可能想看看做一個CGI腳本。 http://wiki.python.org/moin/CgiScripts – NeilMonday

+0

我製作了一個一次性Web服務器來協助完成此操作。看看https://github.com/happygiraffe/logss/blob/master/oneshot.py,以及如何在logss.py中使用它。 –

相關問題