1

Just started to use gdata (Python). Surprisingly, after setting up credentials correctly, I just get HTTP code 400, whenever I try to retrieve all files. Take a look into this code:

s = 'https://www.google.com/m8/feeds'
s = 'https://www.google.com/m8/feeds/contacts/default/full/'

client_secret = CLIENT_SECRET
client_id = CLIENT_ID

client = gdata.contacts.client.ContactsClient()
auth2token = gdata.gauth.OAuth2Token(
        client_id = client_id,
        client_secret = client_secret,
        scope = s,
        user_agent = "bla")
auth2token.authorize(client)

try:
    feed = client.get_contacts()
except gdata.client.RequestError as e:
    print e.args
    print e.body
    print e.headers
    print e.message
    print e.reason
    print e.status

Unfortunatelly I always get error, no matter what the value of s is. See the output of this code:

('Server responded with: 400, ',)

[('alternate-protocol', '443:quic,p=0.08'), ('x-xss-protection', '1; mode=block'), ('x-content-type-options', 'nosniff'), ('transfer-encoding', 'chunked'), ('accept-ranges', 'none'), ('expires', 'Fri, 01 Jan 1990 00:00:00 GMT'), ('vary', 'Accept-Encoding'), ('server', 'GSE'), ('pragma', 'no-cache'), ('cache-control', 'no-cache, no-store, max-age=0, must-revalidate'), ('date', 'Tue, 03 Mar 2015 02:12:08 GMT'), ('x-frame-options', 'SAMEORIGIN'), ('content-type', 'application/json')]
Server responded with: 400, 
Bad Request
400

Any clue?

Thanks!

Silas
  • 392
  • 1
  • 4
  • 15
  • 1
    this answer may help: http://stackoverflow.com/questions/10188768/google-contacts-import-using-oauth2-0 – Gerardo Mar 03 '15 at 19:08
  • Thank you for the link. It seems these solutions (with OAuth2), at least the examples I see in the web, are for web applications only, not standalone applications that run in a computer. I could retrieve contacts information using ordinary user/password login :-/. Thanks. – Silas Mar 04 '15 at 17:02

1 Answers1

0

I suspect the issue may be in the re-authentication i.e. this flow:

  1. you allow your app access
  2. maybe you didn't save the tokens
  3. If you go to allow the already permitted app access again this time saving the tokens.

Tokens using the tokens from (3) give me a 400 error. However, if I:

  1. Go to my google account and unlink the connection between my local app and my contacts
  2. Delete all tokens locally, and then re-authenticate it seems to work fine.
Aaron
  • 801
  • 1
  • 7
  • 12