Hi,

There are many changes with the new v2 classes, I've adapted the
following:
http://gdatatips.blogspot.com/2008/11/2-legged-oauth-in-python.html

and created a small Python 2-legged example (I think we need to get
some help from the Python lib contributors to make a better one):

self.gd_client = gdata.contacts.client.ContactsClient();

CONSUMER_KEY = 'DOMAIN.com'
CONSUMER_SECRET = 'WiR/....'
CONTACTS_URL = 'http://www.google.com/m8/feeds/profiles/domain/
DOMAIN.com/full/'

user = '[email protected]'
params = {'max-results': 100, 'xoauth_requestor_id': user}

oauthconsumer = gdata.auth.oauth.OAuthConsumer
(CONSUMER_KEY,CONSUMER_SECRET)
request = gdata.oauth.OAuthRequest.from_consumer_and_token
( oauthconsumer, http_method='GET', http_url=CONTACTS_URL,
parameters=params)
request.sign_request(gdata.oauth.OAuthSignatureMethod_HMAC_SHA1(),
oauthconsumer, None)
headers = request.to_header()
uri = '%s?%s' % (request.http_url, urllib.urlencode(params))
http_request = atom.http_core.HttpRequest(headers=headers)

feed = self.gd_client.GetFeed(uri, http_request=http_request,
desired_class=gdata.contacts.data.ContactsFeed)
for entry in feed.entry:
  self.PrintEntry( entry )

def PrintEntry(self, entry):
  print '\n%s' % (entry.title.text)

Please if you used this to make a better example, share it back :)

Cheers,
Julian



On Dec 2, 4:40 pm, Manish Bhargava <[email protected]> wrote:
> Thanks Julian!! This is very helpful.
>
> One quick question: I am trying to use this with 2-legged OAuth token in
> AppEngine instead of using ClientLogin which requires user password.
>
> When I was using ContactsService, I was doing:
> gContacts.SetOAuthInputParameters(SETTINGS['SIG_METHOD'],
> SETTINGS['CONSUMER_KEY'],
>                               consumer_secret=SETTINGS['CONSUMER_SECRET'],
>                                   two_legged_oauth=True,
> requestor_id=admin_id)
>
> I do not see any equivalent 'SetOAuthInputParameter' function in
> ContactsClient pydocs, using this setter gives error. Am I missing
> something?
>
> Thanks for your help!!
>
>
>
> On Wed, Dec 2, 2009 at 7:34 PM, Julian (Google) <[email protected]> wrote:
> > Hi,
>
> > The new code for Contacts and Profiles v3 was released with the Python
> > client library 2.0.5, here is a small example that uses the
> > pagination:
>
> > import sys
> > import getopt
> > import getpass
> > import atom
>
> > import gdata.contacts.client
> > import gdata.contacts.data
> > import gdata.data
>
> > class ContactsSample(object):
> >  """ContactsSample object demonstrates operations with the Contacts
> > feed."""
>
> >  def __init__(self, email, password, domain):
> >    self.gd_client = gdata.contacts.client.ContactsClient();
> >    self.gd_client.client_login(email, password, 'TestApp')
> >    url = self.gd_client.GetFeedUri
> > (kind='profiles',contact_list=domain)
> >    while url != None:
> >      feed = self.gd_client.GetFeed
> > (url,desired_class=gdata.contacts.data.ProfilesFeed)
> >      for entry in feed.entry:
> >        self.PrintEntry( entry )
> >      if feed.get_next_link():
> >        url = feed.get_next_link().href
> >      else:
> >        url = None
>
> >  def PrintEntry(self, entry):
> >    """Prints out the contents of a single Entry to the console.
>
> >    Args:
> >      entry: A gdata.contacts.data.ContactEntry
> >    """
> >    print '\n%s' % (entry.title.text)
> >    # more...
>
> > def main():
>
> >  try:
> >    sample = ContactsSample('[email protected]', 'PASSWORD',
> > 'DOMAIN.com')
> >  except gdata.client.BadAuthentication:
> >    print 'Invalid user credentials given.'
> >    return
>
> > if __name__ == '__main__':
> >  main()
>
> > On Dec 2, 1:23 am, Apps Guru <[email protected]> wrote:
> > > Any updates will be highly appreciated. I am stuck :(
>
> > > On Nov 24, 10:42 pm, Manish Bhargava <[email protected]> wrote:
>
> > > > Thanks Julian for the advice.
>
> > > > My problem is that I am calling this from AppEngine for paging through
> > > > domain users. When max-results are more than 200, the AppEngine times
> > out
> > > > because of the time taken(I am populating AppEngine db with values from
> > > > profile feed for individual profile) which times out.
>
> > > > So I cannot rely on max-results. Do you have any idea when this will be
> > > > fixed. I am happy to take a patch from trunk as and when it becomes
> > > > available.
>
> > > > Thanks!!
>
> > > > On Tue, Nov 24, 2009 at 8:49 AM, Julian (Google) <[email protected]>
> > wrote:
> > > > > Hi,
>
> > > > > I was able to reproduce the problem you mention and we are
> > > > > investigating it.
>
> > > > > In the mean time, you could use a bigger number for max-results to
> > get
> > > > > your whole profiles list, for example using the following URL:
>
> >http://www.google.com/m8/feeds/profiles/domain/DOMAIN.COM/full?max-re...
>
> > > > > Cheers,
> > > > > Julian
>
> > > > > On Nov 23, 8:48 am, Apps Guru <[email protected]> wrote:
> > > > > > Hi,
> > > > > >   When I try to use Profiles feed functionality in python 2.0.4,
>
> > > > > > I am able to get 60 results by calling GetProfilesFeed() - 60 is
> > > > > > default number that is returned
>
> > > > > > After that when I call GetProfilesFeed(next.href) - it does not
> > work,
> > > > > > it keeps giving me first sixty results. I have checked the href
> > value,
> > > > > > it looks fine.
>
> > > > > > I tried getting the profiles via query parameter - it seems
> > > > > > q.start_index is not supported for profiles, it always starts from
> > 1
> > > > > > irrespective of its value.
>
> > > > > > Can you please look into this. I need to page through the various
> > > > > > profiles of 250 domain users.
>
> > > > > > Am I doing something wrong or is this is bug in API code?
>
> > > > > > Any help is appreciated.
>
> > > > > > Thanks!!
>
> > > > > --
>
> > > > > You received this message because you are subscribed to the Google
> > Groups
> > > > > "Google Contacts API" group.
> > > > > To post to this group, send email to
> > [email protected].
> > > > > To unsubscribe from this group, send email to
> > > > > [email protected]<google-contacts-api%2Bunsu
> > > > >  [email protected]><google-contacts-api%2Bunsu
> > ­[email protected]>
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/google-contacts-api?hl=en.-Hidequoted
> > text -
>
> > > > - Show quoted text -
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Google Contacts API" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<google-contacts-api%2Bunsu 
> > [email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-contacts-api?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"Google Contacts API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-contacts-api?hl=en.


Reply via email to