Dear Alex,

Thankyou for that it works. Are you also able to help me with how I
attach this to my script that subscribes a user to a calendar.
Currently it uses programtic login to do this. From looking at the
doco it looks like I could use SetAuthSubToken(self, token,
scopes=None), but when I went to the Auth website it indicated that
OAuth and AuthSub were different, so it looks like OAuth may not be
supported for the GData service as yet which is where the Auth calls
seem to come from.

Being able to use OAuth with the consumer secret means that I will be
able to subscribe custom calendars to users without their credentials
which will be very useful.

Yours sincerely

David Ruwoldt

#!/usr/bin/python
#
# Copyright (C) 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
# See the License for the specific language governing permissions and
# limitations under the License.


__author__ = '[EMAIL PROTECTED] (Ryan Boyd)'
# modified: [EMAIL PROTECTED] 20080904

try:
  from xml.etree import ElementTree
except ImportError:
  from elementtree import ElementTree
import gdata.calendar.service
import gdata.service
import atom.service
import gdata.calendar
import atom
import getopt
import sys
import string
import time


class CalendarUpdater:

  def __init__(self, email, password):
    """Creates a CalendarService and provides ClientLogin auth details
to it.
    The email and password are required arguments for ClientLogin.
The
    CalendarService automatically sets the service to be 'cl', as is
    appropriate for calendar.  The 'source' defined below is an
arbitrary
    string, but should be used to reference your name or the name of
your
    organization, the app name and version, with '-' between each of
the three
    values.  The account_type is specified to authenticate either
    Google Accounts or Google Apps accounts.  See gdata.service or
    http://code.google.com/apis/accounts/AuthForInstalledApps.html for
more
    info on ClientLogin.  NOTE: ClientLogin should only be used for
installed
    applications and not for multi-user web applications."""

    self.cal_client = gdata.calendar.service.CalendarService()
    self.cal_client.email = email
    self.cal_client.password = password
    self.cal_client.source = 'Google-
Calendar_Python_UofA_Calendar_Updater-1.0'
    self.cal_client.ProgrammaticLogin()


  def _InsertSubscription(self, id):
    """Subscribes to the calendar with the specified ID."""
    print 'Subscribing to the calendar with ID: %s' % id
    calendar = gdata.calendar.CalendarListEntry()
    calendar.id = atom.Id(text=id)
    returned_calendar = self.cal_client.InsertCalendarSubscription
(calendar)
    return returned_calendar

  def Run(self, groupCalendarName, delete='false'):
    """Runs each of the example methods defined above.  Note how the
result
    of the _InsertSingleEvent call is used for updating the title and
the
    result of updating the title is used for inserting the reminder
and
    again with the insertion of the extended property.  This is due to
the
    Calendar's use of GData's optimistic concurrency versioning
control system:
    http://code.google.com/apis/gdata/reference.html#Optimistic-concurrency
    """

    # Insert Subscription
    inserted_subscription = self._InsertSubscription
(groupCalendarName)


def main():
  """Runs the CalendarExample application with the provided username
and
  and password values.  Authentication credentials are required.
  NOTE: It is recommended that you run this sample using a test
account."""

  # parse command line options
  try:
    opts, args = getopt.getopt(sys.argv[1:], "", ["user=", "pw=",
"delete=", "calendar="])
  except getopt.error, msg:
    print ('subscribeCalendar.py --user [username] --pw [password] ' +
        '--calendar [groupcalendarname] --delete [true|false] ')
    sys.exit(2)

  user = ''
  pw = ''
  delete = 'false'
  groupCalendarName = ''

  # Process options
  for o, a in opts:
    if o == "--user":
      user = a
    elif o == "--pw":
      pw = a
    elif o == "--delete":
      delete = a
    elif o == "--calendar":
      groupCalendarName = a

  if user == '' or pw == '':
    print ('subscribeCalendar.py --user [username] --pw [password] ' +
        '--calendar [groupcalendarname] --delete [true|false] ')
    sys.exit(2)

  sample = CalendarUpdater(user, pw)
  sample.Run(groupCalendarName, delete)

if __name__ == '__main__':
  main()


On Nov 12, 3:56 pm, "Alex (Google)" <[EMAIL PROTECTED]> wrote:
> Hi David,
>
> We're in the process of documenting that new feature better.  Below is
> a snippet which uses the Python OAuth library from:
>
> http://code.google.com/p/oauth
>
> import httplib
> import oauth.oauth as oauth
>
> CONSUMER_KEY='domain.com'
> CONSUMER_SECRET='XXXXXYYYYYZZZZZ'
> USER='[EMAIL PROTECTED]'
> CONTACTS_URL='http://www.google.com/m8/feeds/contacts/default/full'
>
> consumer = oauth.OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET)
> request = oauth.OAuthRequest.from_consumer_and_token
> (consumer,http_url=CONTACTS_URL, parameters={'xoauth_requestor_id':
> USER})
> request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(), consumer,
> None)
>
> connection = httplib.HTTPConnection('www.google.com')
> connection.request('GET', '%s?%s' % (CONTACTS_URL, request.to_postdata
> ()))
> print connection.getresponse().read()
>
> -alex
>
> On Nov 10, 5:48 pm, David Ruwoldt <[EMAIL PROTECTED]> wrote:
>
> > Dear Anirudh,
>
> > Do you have any python code that shows how to use OAuth with the
> > consumer secret?
>
> > Yours sincerely
>
> > David Ruwoldt
>
> > On Nov 10, 8:49 pm, dlw0193 <[EMAIL PROTECTED]> wrote:
>
> > > Thanks so much. That worked like a charm. Looks like I'm ready to try
> > > learning a new language!
>
> > > Thanks again,
>
> > > Darrell
>
> > > On Nov 10, 4:57 am, "Anirudh (Google)" <[EMAIL PROTECTED]> wrote:
>
> > > > Hi,
>
> > > > The methods required for Authentication are provided in the library.
> > > > Here is the code that you would need to write to authenticate yourself
> > > > and say update the signature:
>
> > > > import gdata.apps.emailsettings.service
>
> > > > service = gdata.apps.emailsettings.service.EmailSettingsService
> > > > (email="[EMAIL PROTECTED]", password="pass", domain="domain.com")
> > > > service.ProgrammaticLogin()
> > > > service.UpdateSignature( username="user", signature="howdy")
>
> > > > We do have a Java/Swing based GUI client available for Email Settings
> > > > API. It is bundled with Java GData 
> > > > library:http://code.google.com/p/gdata-java-client/downloads/list
>
> > > > We also acknowledge the need for better language specific guides for
> > > > various APIs provided and will take your query as valuable feedback
> > > > regarding the same.
>
> > > > -Anirudh
>
> > > > On Nov 9, 8:28 am, dlw0193 <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi all,
>
> > > > > I am trying to get started using the gmail settings API. I have
> > > > > downloaded Python 2.6 and the GData library.
>
> > > > > I have almost no programming experience. I'm able to run some of the
> > > > > samples included in the GData library and access my personal GDocs.
> > > > > However, I can't seem to find the correct code to get an
> > > > > authentication token to use in accessing gmail settings for my Apps
> > > > > account.
>
> > > > > Can anyone point me in the right direction or provide the Python  code
> > > > > I need to use?
>
> > > > > On a related note, are there any slick GUIs available that simplify
> > > > > using the APIs?
>
> > > > > Thanks in advance.
>
> > > > > D
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Apps APIs" 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-apps-apis?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to