2012-01-20 11 views
1

Google for Pythonで提供されているgdataライブラリを使用して、Google Appsドメインからプロフィールフィードを取得しようとしています。Google Appsからのプロフィールフィードの入手

C:\Python27\Lib\gdata-2.0.16>python contactAPI.py 
Enter max return: 300 
Traceback (most recent call last): 
    File "contactAPI.py", line 27, in <module> 
    feed_uri = gd_client.GetProfilesFeed() 
    File "build\bdist.win-amd64\egg\gdata\contacts\service.py", line 294, in GetProfilesFeed 
    File "build\bdist.win-amd64\egg\gdata\service.py", line 1108, in Get 
gdata.service.RequestError: {'status': 403, 'body': 'Version 1.0 is not supported.', 'reason': 'Forbidden'} 

私はGetContactsFeedや他のフィードを使用することが、私は、プロファイルを取得することはできません。これは私がこれを実行すると、それは返す私のコード

import atom 
import gdata.auth 
import gdata.contacts 
import gdata.contacts.service 

gd_client = gdata.contacts.service.ContactsService() 
gd_client.email = '[email protected]' 
gd_client.password = 'password' 
gd_client.source = 'madeupgibberish' 
gd_client.account_type = 'HOSTED' 
gd_client.contact_list = 'domain.com' 
gd_client.ProgrammaticLogin() 

def PrintFeed(feed): 
    for i, entry in enumerate(feed.entry): 
    print '\n%s %s' % (i+1, entry.title.text) 

max_results = raw_input(
    'Enter max return: ') 
feed_uri = gd_client.GetProfilesFeed() 
query = gdata.contacts.service.ContactsQuery(feed_uri) 
print(feed_uri) 
query.max_results = max_results 
#query.orderby='title' 
feed = gd_client.GetContactsFeed(query.ToUri()) 
# Use the print feed method defined above. 
PrintFeed(feed) 
print(feed_uri) 
#print feed 

f = open('c:\\python27\\junk.xml', 'w') 
f.write(str(feed)) 
f.close() 

です。ここで何が起きているのか、何を修正する必要があるのでしょうか?ご協力いただきありがとうございます。

答えて

2

gdata.contacts.serviceでは廃止予定のバージョンのAPIが使用されています。代わりにgdata.contacts。{クライアント、データ}を使用する必要があります。
ここでは、ユーザープロファイルを取得するサンプルを示します。

import atom 
import gdata.auth 
import gdata.contacts 
import gdata.contacts.client 
email = '[email protected]' 
password = 'password' 
domain = 'domain.com' 

gd_client = gdata.contacts.client.ContactsClient(domain=domain) 
gd_client.ClientLogin(email, password, 'madeupgibberish') 
def PrintFeed(feed): 
    for i, entry in enumerate(feed.entry): 
    print '\n%s %s' % (i+1, entry.title.text) 

feed_link = atom.data.Link(gd_client.GetFeedUri(kind='profiles')) 
while feed_link: 
    profiles_feed = gd_client.GetProfilesFeed(uri=feed_link.href) 
    PrintFeed(profiles_feed) 
    feed_link = profiles_feed.GetNextLink() 

library's contact_sample.pyとクライアント、データファイルとunshare_profiles.py作品。

+0

これは素晴らしい結果でしたが、60項目しか返しませんでした。私はmax_resultsを追加しようとしていますが、まだ60点しか得ていません。 – Kevin

+0

すべてのプロファイルエントリを取得するコードを編集しました。 – Shadow

関連する問題