I am trying to update the a Google Apps profile picture. I am
following the instructions here: 
http://code.google.com/googleapps/domain/profiles/developers_guide.html

My code looks like so :

import atom.data
import gdata.data
import gdata.contacts.client
import gdata.contacts.data
import cgi
import wsgiref.handlers

from google.appengine.api import users
from google.appengine.ext import webapp

email = '[email protected]'
password = 'password'
domain = 'domain.com'

gd_client = gdata.contacts.client.ContactsClient(domain=domain)
gd_client.ClientLogin(email, password, 'photoUpdate',
account_type="HOSTED")


class PicPage(webapp.RequestHandler):
        def get(self):
                self.response.out.write("""<html><head><title>Domain Photo 
Uploader</
title>
                                                                        <link 
type="text/css" rel="stylesheet" href="/stylesheets/
form.css"></head>
                                                                        <body>
                                                                        <form 
action="/" enctype="multipart/form-data" method="post">
                                                        <div><label>Person 
Name</label></div>
                                                        <div><textarea 
name="name" rows="2" columns "60"></
textarea></div>
                                                        
<div><label>Image</label></div>
                                                        <div><input type="file" 
name="img"/></div>
                                                        <div><input 
type="submit" value="Upload" /></div>
                                                                </form>
                                                                </body>
                                                                </html>""")

        def post(self):
                person_name = self.request.get('name')
                person_name2 = str(person_name)
                img_img = self.request.get('img')
                profile_url = "https://www.google.com/m8/feeds/photos/profile/
domain.com/person"
                profile_url2 = str(profile_url)
                print profile_url
                ms = gdata.data.MediaSource(img_img, 'image/jpeg')
                media_object = ms
                print(profile_url)
                def update_profile_photo(gd_client, profile_url, media_object):
                        profile = gd_client.GetProfile(profile_url)

                        try:
                                gd_client.ChangePhoto(media_object, profile)
                        except gdata.client.RequestError, e:
                                if e.status == 412:
                                # Etags mismatch: handle the exception.
                                        pass
                        print "Yup!!!!"
                update_profile_photo(gd_client,profile_url2,media_object)
                #profile = gd_client.GetProfile(profile_url)
                #print(profile)
                #gd_client.ChangePhoto(media_object, profile)
                self.redirect('/')

def main():
  application = webapp.WSGIApplication(
                                       [('/', PicPage)
                                        ],
                                       debug=True)

  wsgiref.handlers.CGIHandler().run(application)

if __name__=="__main__":
  main()

Whenever this runs I get this as a response:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
\ext\webapp\_webapp25.py", line 703, in __call__
    handler.post(*groups)
  File "C:\GAE_Local_Files\picupload\sasakipic.py", line 54, in post
    update_profile_photo(gd_client,profile_url2,media_object)
  File "C:\GAE_Local_Files\picupload\sasakipic.py", line 45, in
update_profile_photo
    profile = gd_client.GetProfile(profile_url)
  File "C:\GAE_Local_Files\picupload\gdata\contacts\client.py", line
375, in get_profile
    auth_token=auth_token, **kwargs)
  File "C:\GAE_Local_Files\picupload\gdata\client.py", line 652, in
get_entry
    desired_class=desired_class, **kwargs)
  File "C:\GAE_Local_Files\picupload\gdata\client.py", line 278, in
request
    version=get_xml_version(self.api_version))
  File "C:\GAE_Local_Files\picupload\atom\core.py", line 520, in parse
    tree = ElementTree.fromstring(xml_string)
  File "<string>", line 106, in XML
ParseError: not well-formed (invalid token): line 1, column 0

I have gone through this line by line in interactive mode, and it is
failing on:
profile = gd_client.GetProfile(profile_url)

I have no idea with the why this is breaking, please help, I am
exasperated.

-- 
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

Reply via email to