hermanho / MMM-GooglePhotos

Display your photos on MagicMirror from Google Photos.
MIT License
170 stars 65 forks source link

node generate_token.js error #135

Closed sirfox70 closed 2 years ago

sirfox70 commented 2 years ago

Hi,

I am having trouble with node generate_token.js error as below, Everything worked find before that. I installed MMM-GooglePhotos several times but it is still same.

pi@raspberrypi:~/MagicMirror/modules/MMM-GooglePhotos $ node generate_token.js

Cannot read property '0' of undefined /home/pi/MagicMirror/modules/MMM-GooglePhotos/GPhotos.js:133 throw e ^

TypeError: Cannot read property '0' of undefined at new Auth (/home/pi/MagicMirror/modules/MMM-GooglePhotos/GPhotos.js:35:91) at GPhotos.onAuthReady (/home/pi/MagicMirror/modules/MMM-GooglePhotos/GPhotos.js:130:14) at GPhotos.generateToken (/home/pi/MagicMirror/modules/MMM-GooglePhotos/GPhotos.js:141:10) at Object. (/home/pi/MagicMirror/modules/MMM-GooglePhotos/generate_token.js:10:9) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) at internal/main/run_main_module.js:17:47

Please help.

Moawin99 commented 2 years ago

Is your app in google console registered as a "Desktop app"? I was just getting this issue and changing to that fixed it

JustinBa commented 2 years ago

Hey, I have the exact same error with same messages.

I can say that I do have (TVs and limited input devices) selected, not desktop app

sirfox70 commented 2 years ago

Is your app in google console registered as a "Desktop app"? I was just getting this issue and changing to that fixed it

Thanks a lot for your reply. In the Register model screen, I could not find "Desktop app" in Device type. So I selected "Scene" but it is still the same.

sirfox70 commented 2 years ago

Hey, I have the exact same error with same messages.

I can say that I do have (TVs and limited input devices) selected, not desktop app

Thanks, I could not find "desktop app" in the Register model, I will try to change "TV" and try again. Thanks again.

sirfox70 commented 2 years ago

Is your app in google console registered as a "Desktop app"? I was just getting this issue and changing to that fixed it

Thanks a lot for your reply. In the Register model screen, I could not find "Desktop app" in Device type. So I selected "Scene" but it is still the same.

Now, I understand that I could select "Desktop app" in the OAuth 2.0 Client ID, and I changed to "TV and limited input device" and copied the .json file to the MMM-GooglePhotos folder, but I still have the same error.

lnk64 commented 2 years ago

@sirfox70 Try the steps listed here.

You basically have to recreate oauth credentials for a desktop app, download the .json file, use the generate_token.js to make a new token with the new .json file you just download AND clear out the existing contents of the cache folder within MMM-GooglePhotos. Hopefully that will get you going

sirfox70 commented 2 years ago

Thanks, Ink64.

I tried to create oauto crendentials for a desktop app. but another error message shows as;

[GPHOTOS:AUTH] Token is expired. (node:2169) UnhandledPromiseRejectionWarning: Error: invalid_grant at createError (/home/pi/MagicMirror/modules/MMM-GooglePhotos/node_modules/google-auth-library/node_modules/axios/lib/core/createError.js:16:15) at settle (/home/pi/MagicMirror/modules/MMM-GooglePhotos/node_modules/google-auth-library/node_modules/axios/lib/core/settle.js:18:12) at IncomingMessage.handleStreamEnd (/home/pi/MagicMirror/modules/MMM-GooglePhotos/node_modules/google-auth-library/node_modules/axios/lib/adapters/http.js:202:11) at IncomingMessage.emit (events.js:412:35) at endReadableNT (internal/streams/readable.js:1334:12) at processTicksAndRejections (internal/process/task_queues.js:82:21) (Use node --trace-warnings ... to show where the warning was created) (node:2169) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:2169) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I really do not know what is wrong. I change the google account and even I open a new account but all failed.

What do I need more to use MMM-GooglePhotos? Thanks,

lnk64 commented 2 years ago

Yeah im not sure. Im not the owner of the repo, just a guy who picks things apart, haha. With that said, the module does a comparison of the current date of your system and compares it to the expiry_date found within your existing token.json file (which is generated by generate_token.js).

If the token's date is older then today, then you'll get the message.

When you downloaded the credentials file from google, did you delete the existing token.json file before attempting to run generate_token.js ? Im not sure if the generate_token.js will overwrite the old token if its there. And are you able to validate that your system date and time is correct?

I'd also be curiouse about the date on both your credentials.jon file and your token.json file, just to verify if they correspond to the dates you downloaded & generated your credentials/token.

Just trying to throw out ideas here. :)

lnk64 commented 2 years ago

Another thought, i remember receiving a similar error regarding UnhandledPromiseRejectionWarning: Unhandled promise rejection. and im wondering if the same is happening for you.

Inside your config for MMM-GooglePhotos, you have an array of Albums to scan. For example my config is : albums: ["Slideshow","MirrorSelfie"],

I found that the code would attempt to go through both albums, grab the first photo in each album to then figure out how to construct the URLs. However, if any album has no images in it whatsoever, then it would generate that error.

I would try and place at least one picture in your photo album(s) if you do not have one already and see if that removes the error for you

sirfox70 commented 2 years ago

Thanks a lot, Ink64.

I tried again to install the new raspberry pi OS, and I set the time and I selected "Desktop app" in the OAuth 2.0 Client ID. I checked the time and the date were no issue.

after I type $ node generate_token.js

wow, I finally could see the >Paste your code and then browser screen... I am sooooooo happy to see only this screen.

And, I choose my account and continued... and select two options and press next button but it shows "Connection refused from localhost" and I could not continue further.

I should dig more and more... Thanks a lot again.

lnk64 commented 2 years ago

Ive gotten that error before. You can still move past it. On the page were it says localhost connection refuse, the code that the terminal is waiting for is at the top embedded within the URL between code= and &scope= It'll start something akin to: code=4/0AX.........joA&scope=

Just copy and paste that middle part into the terminal and you should be able to proceed

sirfox70 commented 2 years ago

Thanks a million! Ink64. It works now haha, I copied and paste the code shown on the address. I am so grateful. God bless you.

bojuelkjeldsen commented 2 years ago

Ive gotten that error before. You can still move past it. On the page were it says localhost connection refuse, the code that the terminal is waiting for is at the top embedded within the URL between code= and &scope= It'll start something akin to: code=4/0AX.........joA&scope=

Just copy and paste that middle part into the terminal and you should be able to proceed

This just worked for me also, thanks alot!

tails251 commented 1 year ago

Ive gotten that error before. You can still move past it. On the page were it says localhost connection refuse, the code that the terminal is waiting for is at the top embedded within the URL between code= and &scope= It'll start something akin to: code=4/0AX.........joA&scope=

Just copy and paste that middle part into the terminal and you should be able to proceed

Hi, Ink64, apologies if this is a silly question but I'm having the same issue and am trying to copy the code from the url but not successfully. I'm getting a throw new error, and error getting tokens error.

Do we start the copy paste from the 4th character after the 4/, and then end it the final character before the &scope?

lnk64 commented 1 year ago

Hey, sorry I just saw this. It's been a long time since i messed with Magic Mirror stuff, so Google may have changed things since my comment last year. With that said, I think you copy the whole thing even before the 4/.

So if the URL was code=4/0AX..... JO&scope, then the content you want to copy is everything between = to the &scope.

So is the code was code=4/0AXIDon'tKnowThisisArandomCode&scope=

Then you should copy 4/0AXIDon'tKnowThisisArandomCode into the terminal

Hope that helps!