Forgot to attach my files...

On Thursday, April 19, 2012 5:16:25 AM UTC-5, Githlar wrote:
>
> I'm writing an application to manage customers my my soon-to-be business 
> and I was successfully able to set appointments to my Google Calendar 
> (handy for my Android phone), but I would also like to add my clients to my 
> address book from the application as an added convenience. The issue I am 
> having is that when I attempt to add a Contact, I get a "401 - 
> Unauthorized" error. I can only assume this is because I'm not passing the 
> acquired authentication to the Contacts client.
>
> I'm very new to the Google API and it's all pretty overwhelming to me, but 
> I've attached the code I use to do the Calendar appointments (which works) 
> and to add Contacts. I set up the authorization in the gcalendar.py file 
> with an added scope for Contacts, but every time I try to add a contact, I 
> get the aforementioned error. Most of this is compiled from example code - 
> so, quite honestly, I'm still a little sketchy on how it fits together 
> (even after looking over the gdata-python-client documentation). I would 
> assume that once the authorization is obtained it would carry on for all 
> further requests for authorized services (and the authorization does ask 
> for Calendar and Contacts access), but I initialize the Calendar service in 
> a different way than I try to use Contacts. This is because I've seen no 
> examples similar to the Calendar example for use with Contacts.
>
> If somebody could point me in the right direction here it would be greatly 
> appreciated.
>
> P.S. I suppose it is worth noting that this is not a web-app but a console 
> application as I believe it's referred to. It runs on my computer as a 
> stand-alone Python application.
>

-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles 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://code.google.com/apis/contacts/community/forum.html

Attachment: gcalendar.py.tmp
Description: Binary data

import atom.data
import gdata.data
import gdata.contacts.client
import gdata.contacts.data
import gdata
import datetime
from common import *

gd_client = gdata.contacts.client.ContactsClient(source='v1')
gd_client.ssl = True
# Authorize the client.
#def setup_contacts()
#    global service
#    global contacts
#    # Build a service object for interacting with the API. Visit
#    # the Google APIs Console
#    # to get a developerKey for your own application.
#    service = build(serviceName='contacts', version='3.0', http=http, developerKey="AIzaSyBNOE1p-fcQYPrm6PhmE16nzEBPL4xYOko")
           
#    contacts = service.contacts().get(calendarId=calendar_id).execute()
    
def fetchContact():
    pass

def createContact(con_name, con_address, con_phone, con_email):
  print "con_name", con_name
  print "con_address", con_address
  print "con_phone", con_phone
  print "con_email", con_email
  new_contact = gdata.contacts.data.ContactEntry(name=gdata.data.Name(full_name=gdata.data.FullName(text=con_name)))
  new_contact.content = atom.data.Content(text=con_name)
  #new_contact = gdata.contacts.data.ContactEntry(
  #                name=gdata.data.Name(full_name=gdata.data.FullName(text=con_name)))
  #new_contact.name.append(gdata.data.Name(full_name=gdata.data.FullName(text=con_name)))
  #new_contact.phone_number.append(gdata.data.PhoneNumber(text=con_phone,rel=gdata.contacts.REL_HOME,primary="true"));
  #new_contact.postal_address.append(gdata.data.FormattedAddress(text=con_address));
  #new_contact.email.append(gdata.data.Email(address=con_email,rel=gdata.data.HOME_REL,primary="true"));
#                  phone_number=gdata.contacts.PhoneNumber(text=con_phone,rel=gdata.contacts.REL_HOME),
#                  postal_address=gdata.data.FormattedAddress(text=con_address),
#                  email=gdata.data.Email(text=con_email)
#                )
  entry = gd_client.AddContact(new_contact)
  
  if entry:
    print 'Created contact!'
    print 'ID for the new contact:', entry.id.text
  else:
    print 'Add contact failure.'  

if __name__ == "__main__":
  print "Creating contact..."
  createContact("Sum Dum Gai","123 Fake Street, Newton KS","5555555555","[email protected]");
#  print "Fetch contact..."
#  fetchContact();
#  print "Deleting contact..."
#  deleteContact();

Reply via email to