[英]Error using Google Assistant Library with Raspberry Pi 3 and Python (Credentials not accepted)
I successfully managed to get Google's Assistant working on my Raspberry Pi 3. It works by using 我成功地使Google的Assistant在我的Raspberry Pi 3上运行。
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. 现在,我想使用python进行访问,以在识别特定命令时打开/关闭LED。 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. 我试图重新安装所有内容,还重新下载了json文件。 Obviously the json doesn't get recognized properly, but I don't have any clue what to do.
显然,无法正确识别json,但是我不知道该怎么做。 My JSON looks like this:
我的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"]}}
here is what the Credentials class is expecting: http://google-auth.readthedocs.io/en/latest/reference/google.oauth2.credentials.html 以下是凭据类的期望: http : //google-auth.readthedocs.io/zh_CN/latest/reference/google.oauth2.credentials.html
I hope you guys can help me with this. 我希望你们能帮助我。 Thanks a lot in advance!
在此先多谢!
I just figured it out. 我只是想通了。 The problem was that I was using the wrong json file.
问题是我使用了错误的json文件。 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
您必须移交给python脚本的JSON文件是执行时下载的JSON文件
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. 默认情况下位于/home/pi/.config/google-oauthlib-tool/。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.