0

I would like to display user images in my web app from a users contacts. I have the following:

qry = gdata.contacts.client.ContactsQuery(max_results=10)
feed = gd_client.get_contacts(query=qry)

for cont in feed.entry:
    self.response.out.write(cont.name)                                                
    photo =  cont.GetPhotoLink().href

    self.response.out.write("<img src='"+photo+"'>")

I have no idea why this isn't working as the links it produces seem right per this guide https://developers.google.com/google-apps/contacts/v3/#retrieving_a_contacts_photo

https://www.google.com/m8/feeds/photos/media/currentlyautheduser%40gmail.com/27e1e1d70bb51465

and the gd_client seems to be authed correctly (I can see the contacts other details...)

the code for my contacts client is as following

def AuthedContactsClient():
    current_user = users.GetCurrentUser()
    gd_client = gdata.contacts.client.ContactsClient(source=SETTINGS['APP_NAME'])
    gd_client.ssl=True
    access_token_key = 'access_token_%s' % current_user.user_id()
    gd_client.auth_token = gdata.gauth.ae_load(access_token_key)
    return gd_client

Any ideas? Thanks!

  • Could it be you're trying to view the photo from your browser being (or not being at all) authenticated as a different user? See what response code you get while accessing media resource. If 401, it's probably that. – alex Jun 03 '12 at 12:03
  • I meant, the request to retrieve a contact photo should be authorized, just like any other authorized request you'd do to retrieve contacts data. – alex Jun 03 '12 at 12:11
  • Hmm, the gdata.contacts.client is authorized with the account users credentials and can retrieve other data fine. I'm serving it in the view with getphotolink().href in an image tag. So the requests for other contact data are coming from the server to google (w/Auth code) but presumably the image link request is coming from the browser (w/o authentication??). How can I display the image without storing it in the data store? – user1021311 Jun 04 '12 at 13:29
  • I'm not sure it's possible to display images right from the photo URL of a contact data. One thing you could do though, is retrieve image data asynchronously via AJAX on the client (where you *can* set auth headers) and then inject that data into – alex Jun 04 '12 at 13:56

0 Answers0