簡體   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