0

I want get list of all groups in my contacts. I use that code:

import gdata.gauth
import gdata.contacts.client

token = gdata.gauth.OAuth2Token(client_id = "***.apps.googleusercontent.com",
                                client_secret = "***",
                                scope = "https://www.google.com/m8/feeds/",
                                user_agent = "GC")
gd_client = gdata.contacts.client.ContactsClient(source = 'GCv0.1')
gd_client = token.authorize(gd_client)
gd_client.GetGroups()

But got error:

Traceback (most recent call last):
  File "F:/Yandex/Sites/GoogleContacts/cli_contacts.py", line 27, in <module>
    gd_client.GetGroups()
  File "C:\Users\Ishayahu\27Gdata\lib\site-packages\gdata\contacts\client.py", line 218, in get_groups
    return self.get_feed(uri, desired_class=desired_class, auth_token=auth_token, **kwargs)
  File "C:\Users\Ishayahu\27Gdata\lib\site-packages\gdata\client.py", line 640, in get_feed
    **kwargs)
  File "C:\Users\Ishayahu\27Gdata\lib\site-packages\gdata\client.py", line 319, in request
    RequestError)
gdata.client.RequestError: Server responded with: 400, 
    enter code here

I have no idea what a reason and I can't find any clue how to solve it.

UPD: It looks like I should somehow put acess_token or refresh_token into OAuth2Token, but I can't understand how debuging from PyCharm so it send headers

{'GData-Version': '3', 'Authorization': 'Bearer None', 'User-Agent': 'gdata-py/2.0.17'}

UPD2: by the way, if I test in in OAuth2Playground, it shows me a page with request access to my contacts. That script doesn't ask for it. Maybe that's the problem? How can I change it? I thought, it connect with url_redirect, but I can't uderstand, how to use it

UPD3: I was right: if I add access_token, which I get manualy from Playground, all works. But how should I get it in script?!

Ishayahu
  • 349
  • 1
  • 19
  • Possible duplicate of [Retrieve one contact with python gdata.contacts.client](http://stackoverflow.com/questions/10940187/retrieve-one-contact-with-python-gdata-contacts-client) – DeA Feb 09 '17 at 14:38
  • I'm not sure. 1) I need all groups, not one contact. 2) I've got the same error all the time – Ishayahu Feb 09 '17 at 18:32
  • Did you try the fix they mentioned there? – DeA Feb 09 '17 at 20:55
  • 400's are returned from the server with a description of what is wrong. Can you somehow edit `client.py` to output the raw server response? – Blake O'Hare Feb 09 '17 at 21:49
  • there are no information about error. but it looks like there is a problem with token, because in headers I have `{'GData-Version': '3', 'Authorization': 'Bearer None', 'User-Agent': 'gdata-py/2.0.17'}` and after that I've got error `'Token invalid - Invalid token: Cannot parse referred token string: Invalid gaia_data.AuthSubToken proto on base64 token.'`. It try refresh token, but fails – Ishayahu Feb 10 '17 at 06:28
  • This [SO thread](http://stackoverflow.com/questions/40278900/token-invalid-invalid-token-cannot-parse-referred-token-string-invalid-gaia) might help. It suggested to set Scope only for feed worked. `String[] SCOPESArray = {"https://spreadsheets.google.com/feeds"/*, "https://spreadsheets.google.com/feeds/spreadsheets/private/full", "https://docs.google.com/feeds","https://www.googleapis.com/auth/drive"*/};`. Also, this [forum](https://productforums.google.com/forum/#!msg/docs/SCi5a3JpVjI/Il6oVtA-CAAJ) suggested to create a new service around. – abielita Feb 10 '17 at 09:32
  • I've see it, but it doesn't help – Ishayahu Feb 10 '17 at 09:59

0 Answers0