0

I successfully managed to get Google's Assistant working on my Raspberry Pi 3. It works by using

google-assistant-demo --d device_id1234

Now I want to get access with python to turn on/off an LED when a certain command is recognized. Unfortunately the page I followed isn't free, so I can't provide a link. The problematic part of my code is the following:

def main():
   parser = argparse.ArgumentParser(
       formatter_class=argparse.RawTextHelpFormatter)
   parser.add_argument('--credentials', type=existing_file,
                       metavar='OAUTH2_CREDENTIALS_FILE',
                       default=os.path.join(
                           os.path.expanduser('~/.config'),
                           'google-oauthlib-tool',
                           'credentials.json'
                       ),
                       help='Path to store and read OAuth2 credentials')
   args = parser.parse_args()


   with open(args.credentials, 'r') as f:
       credentials = google.oauth2.credentials.Credentials(token=None,
                                                           **json.load(f))

       with Assistant(credentials) as assistant:
           print("Warte auf Hotword")
           for event in assistant.start():
               process_event(event, assistant)

and when I run the script by

python assistant.py --credentials client_secret_blabla.json

it throws the error

Traceback (most recent call last):
   File "assistant.py", line 137, in <module>
      main()
   File "assistant.py", line 128, in main
      **json.load(f)
TypeError: __init__() got an unexpected keyword argument 'installed'

I tried to reinstall everything and also redownloaded the json file. Obviously the json doesn't get recognized properly, but I don't have any clue what to do. My JSON looks like this:

{"installed":{"client_id":"XXX.apps.googleusercontent.com","project_id":"dotted-nature-182957","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"XXX","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

here is what the Credentials class is expecting: http://google-auth.readthedocs.io/en/latest/reference/google.oauth2.credentials.html

I hope you guys can help me with this. Thanks a lot in advance!

Nick Felker
  • 11,536
  • 1
  • 21
  • 35
Brosch
  • 98
  • 8

1 Answers1

0

I just figured it out. The problem was that I was using the wrong json file. I find the documentation kind of unclear concerning that. The JSON file you have to hand over to the python script is the one which is downloaded when executing

google-oauthlib-tool --client-secrets /home/pi/PREVIOUSLYDOWNLOADEDJSON.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless

which is located at /home/pi/.config/google-oauthlib-tool/ in default.

Brosch
  • 98
  • 8