2011-09-26 9 views
1

방금 ​​"내 주소록"이라는 단어가 내 Google 주소록 목록에있는 모든 그룹을 가져 오는 작은 파이썬 스크립트를 작성했습니다. 3.0 API를 사용 중이며 2.0 API에도 비슷한 문제가있었습니다. 다음은 Google 2.0 Contacts documentation에서 가져온 것입니다."내 주소록"그룹 Google 주소록

예를 들어 내 연락처 그룹의 ID를 확인하려면 특정 사용자에 대한 모든 그룹 피드를 검색 한 다음 하위 요소가있는 그룹 항목을 찾아 해당 그룹 항목의 요소 값을 가져올 수 있습니다 .

현재 응답은 어디서나 gContact : systemGroup 태그가 없습니다. 특정 그룹의 그룹 ID를 얻으려면 어떻게해야합니까? 아래 그림과 같이

내 스크립트입니다 : -

user="[email protected]" 
pas="blah" 
data={"Email":user, "Passwd":pas, "service": "cp", "source":"tester"} 
import urllib 
data = urllib.urlencode(data) 

import urllib2 
req = urllib2.Request('https://www.google.com/accounts/ClientLogin', data) 
resp = urllib2.urlopen(req) 
x = resp.read() 

auth=a[-1].split('=')[-1] 
req = urllib2.Request('https://www.google.com/m8/feeds/groups/[email protected]/full/', headers={'Authorization':'GoogleLogin auth='+auth}) 
resp = urllib2.urlopen(req) 
x = resp.read() 
print x 
print "My Contacts" in x 
print "gContact:systemGroup" in x 

나는이 좋지 않을까 해결 수있는 방법에 대한 몇 가지 단서, 감사합니다.

+0

이 경우 https://www.google.com/m8/feeds/groups/default/full이 도움이 될 수 있습니다. –

답변

2

Python Client Library을 직접 사용하지 않으시겠습니까? 여기에는 정확히을 수행하는 메소드 세트가 포함되어 있습니다.

import gdata.contacts.client 
import gdata.contacts.data # you might also need atom.data, gdata.data 

gd_client = gdata.contacts.data.ContactsClient(source='eQuiNoX_Contacts') 
gd_client.ClientLogin('[email protected]', '**password**') 

feed = gd_client.GetGroups() 
    for entry in feed.entry: 
     print 'Atom Id: %s' % group.id.text 
     print 'Group Name: %s' % group.title.text 
     if not entry.system_group: 
      print 'Edit Link: %s' % entry.GetEditLink().href 
      print 'ETag: %s' % entry.etag 
     else: 
      print 'System Group Id: %s' % entry.system_group.id 

이 문제가 해결 되었습니까? 그것은 어떤면에서는 깨끗합니다. 여전히에 문제가 발생하는 경우 : 어떤 이유로

... "를 내 연락처"... 표시되지 않습니다 문서에서 다음

:

주 : 피드에는 사용자의 연락처 그룹이 모두 포함되지 않을 수 있습니다. 반환되는 결과의 개수에 기본 제한이 있기 때문입니다. 자세한 내용은 max-results 쿼리 매개 변수 Retrieving contact groups using query parameters을 참조하십시오.

참고 : newer documentation에는 프로토콜 설명과 함께 샘플 파이썬 코드가 포함되어 있습니다. 파이썬 코드는 제네릭 프로토콜에 대한 저의 머리를 감싸줍니다.