繁体   English   中英

在Raspberry Pi 3和Python上使用Google Assistant库时出错(不接受凭据)

[英]Error using Google Assistant Library with Raspberry Pi 3 and Python (Credentials not accepted)

我成功地使Google的Assistant在我的Raspberry Pi 3上运行。

google-assistant-demo --d device_id1234

现在,我想使用python进行访问,以在识别特定命令时打开/关闭LED。 不幸的是,我关注的页面不是免费的,因此无法提供链接。 我的代码中有问题的部分如下:

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)

当我运行脚本时

python assistant.py --credentials client_secret_blabla.json

引发错误

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'

我试图重新安装所有内容,还重新下载了json文件。 显然,无法正确识别json,但是我不知道该怎么做。 我的JSON看起来像这样:

{"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"]}}

以下是凭据类的期望: http : //google-auth.readthedocs.io/zh_CN/latest/reference/google.oauth2.credentials.html

我希望你们能帮助我。 在此先多谢!

我只是想通了。 问题是我使用了错误的json文件。 我发现与此有关的文档种类不清楚。 您必须移交给python脚本的JSON文件是执行时下载的JSON文件

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

默认情况下位于/home/pi/.config/google-oauthlib-tool/。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM