开发者

"My Contacts" group google contacts

I just wrote a small python script that gets me all the groups on my google contacts list, however for some reason "My Contacts" does not show up in that. I'm using the 3.0 api and was having similar problems with the 2.0 api too. The following is an except taken from the Google 2.0 Contacts documentation.

To determine the My Contacts group's ID, for example, you can retrieve a feed of all the groups for a given user, then find the group entry that has the subelement, and take the value of that group entry's element.

Currently the response that I get does not have a gContact:systemGroup tag anywhere. How should I proceed in order to get the group id of a particular group?

My script is as shown below:-

user="blah@gmail.com"
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/blah@gmail.com/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

Some clues on how I could troubleshoot this would be awesome, thanks.


Why not use the Python Client Library directly? It includes a set of methods that do exactly what you want.

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('equinox@gmail.com', '**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

Does this solve your problem? It's cleaner, in a way. If you're still having trouble with:

...for some reason "My Contacts" does not show up...

then from the documentation:

Note: The feed may not contain all of the user's contact groups, because there's a default limit on the number of results returned. For more information, see the max-results query parameter in Retrieving contact groups using query parameters.

Note: The newer documentation includes sample Python code side-by-side with the protocol explanation; the Python code helps me wrap my head around the generic protocol.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜