androidthings / sample-googleassistant

Google Assistant API sample for Android Things
Apache License 2.0
467 stars 147 forks source link

Can't create credentials.json #26

Closed Ranjith1992 closed 7 years ago

Ranjith1992 commented 7 years ago

I tried to create credentials.json from my ubuntu system. But iam getting the following error. Step i followed:

google-oauthlib-tool --client-secrets client_secret_181189387533-2oksu7u1qas4n65lgermqejhb2roj68m.apps.googleusercontent.com.json --credentials /home/ranjith/GoogleAssistant/add/credentials.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save

Error Occured :

Traceback (most recent call last): File "/home/ranjith/env/bin/google-oauthlib-tool", line 11, in

sys.exit(main()) File "/home/ranjith/env/lib/python3.5/site-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/home/ranjith/env/lib/python3.5/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/ranjith/env/lib/python3.5/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/ranjith/env/lib/python3.5/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/home/ranjith/env/lib/python3.5/site- packages/google_auth_oauthlib/tool/__main__.py", line 104, in main creds = flow.run_local_server() File "/home/ranjith/env/lib/python3.5/site- packages/google_auth_oauthlib/flow.py", line 414, in run_local_server self.fetch_token(authorization_response=authorization_response) File "/home/ranjith/env/lib/python3.5/site- packages/google_auth_oauthlib/flow.py", line 234, in fetch_token client_secret=self.client_config['client_secret'], KeyError: 'client_secret' Kindly help me to resolve this issue.
tyharness commented 7 years ago

Hello Ranjith1992

Rename the file to client_secret_NNNN.json and copy to the project root directory. You don't have to rename the file but it makes it easier but it must be put in the project root directory.

try:

sudo pip install google-auth-oauthlib[tool] sudo pip install click

google-oauthlib-tool --client-secrets client_secret_NNNN.json --credentials app/src/main/res/raw/credentials.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save

A web page pops up and you choose your google account which then creates and saves the credentials.json in the correct directory.

Build the APK - the build will fail if the credentials.json is not in the res/raw folder.

From the command line: adb connect Android.local ./gradlew assembleDebug adb install -r app/build/ouputs/apk/app-debug.apk (-r to replace a previous version) adb reboot

best regards

CaiWeiLeGG commented 7 years ago

Do the google-oauthlib-tool can run on Windows?if it can,i have get promble with the same,the last error is ....client_secret=self.client_config['client_secret'], KeyError: 'client_secret'

Ranjith1992 commented 7 years ago

I solved this error. While creating client_secret_NNNN.json file i choose "other" instead of "android". Then issue was resolved.If you have same issue,Please try this fix.

CaiWeiLeGG commented 7 years ago

yet!i try it this what you said,but the new question is happend,when i run the application upload the audioRecord to Google Assistant,but the downLoad AudioTrack is Sound noisy!I do not why!

Ranjith1992 commented 7 years ago

Which device your running the application ? what about the audio h/w profile of the device ? Audio is working fine in my HTC nexus 9 tab with high speed wifi.

May be issue due audio h/w profile or low speed internet.

CaiWeiLeGG commented 7 years ago

Ok!my running device is Raspberry pie 3!I creating client_secret_NNN.json file i choose "android".And download client json file,and run command: E:\CaiPro\github\AndroidThings\googleSample\sample-googleassistant>google-oauthlib-tool --client-secrets client_secret.json --credentials app/src/main/res/raw/credentials.json --scope https://www.googleapis.c om/auth/assistant-sdk-prototype --save Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_ty pe=code&client_id=597978834045-pq66vegggovl00osjtf9ho56koiv1k11.apps.googleusercontent.com&redirect_uri=ht tp%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fassistant-sdk-prototype&sta te=wAOe4XJ8d3J2ahcV3wlJqXYi8D14Wi&access_type=offline Traceback (most recent call last): File "f:\developertools\python\lib\runpy.py", line 174, in _run_module_as_main "main", fname, loader, pkg_name) File "f:\developertools\python\lib\runpy.py", line 72, in _run_code exec code in run_globals File "F:\developerTools\python\Scripts\google-oauthlib-tool.exe__main.py", line 9, in File "f:\developertools\python\lib\site-packages\click\core.py", line 722, in call return self.main(args, kwargs) File "f:\developertools\python\lib\site-packages\click\core.py", line 697, in main rv = self.invoke(ctx) File "f:\developertools\python\lib\site-packages\click\core.py", line 895, in invoke return ctx.invoke(self.callback, ctx.params) File "f:\developertools\python\lib\site-packages\click\core.py", line 535, in invoke return callback(args, **kwargs) File "f:\developertools\python\lib\site-packages\google_auth_oauthlib\tool\main__.py", line 104, in ma in creds = flow.run_local_server() File "f:\developertools\python\lib\site-packages\google_auth_oauthlib\flow.py", line 414, in run_local_s erver self.fetch_token(authorization_response=authorization_response) File "f:\developertools\python\lib\site-packages\google_auth_oauthlib\flow.py", line 234, in fetch_token

client_secret=self.client_config['client_secret1'],

KeyError: 'client_secret1'

My developer envirment is windows 7 OS!Not linux

Ranjith1992 commented 7 years ago

while creating client_secret_NNN.json If you choose "android" it will not work. Please choose "other" and it will work.

Note : If your choose android you need another methods to authenticate your android application using Oauth.Please see the below link.

CaiWeiLeGG commented 7 years ago

Dear Ranjith1992, you are right,I should choose the "other" option,now my devices can run on By Google Assistant,thank you for your answer!,the question before is my mircophone was broken!Oh my gad

Ranjith1992 commented 7 years ago

Happy to know it's working :)

TumaLiu commented 2 years ago

Hi Ranjith1992,

while creating client_secret_NNN.json If you choose "android" it will not work. Please choose "other" and it will work.

Note : If your choose android you need another methods to authenticate your android application using Oauth.Please see the below link.

If I insist on choose "Android",how can resolve this error? thanks!