janvda / node-red-contrib-google-photos

Node-RED node for Google APIs using OAuth2.
MIT License
0 stars 0 forks source link

TypeError: Cannot read property 'albums' of null #11

Open janvda opened 4 years ago

janvda commented 4 years ago

The following is logged:

15.12.19 15:02:08 (+0100)  node-red  15 Dec 14:02:08 - [warn] [google:google photos api] node.on('input'):[object Object]
15.12.19 15:02:08 (+0100)  node-red  15 Dec 14:02:08 - [warn] [google:google photos api] get_albums_list ...
15.12.19 15:02:08 (+0100)  node-red  15 Dec 14:02:08 - [error] [google:google photos api] TypeError: Cannot read property 'albums' of null
15.12.19 15:02:08 (+0100)  node-red  15 Dec 14:02:08 - [warn] [google:google photos api] ... end node.on()
janvda commented 4 years ago

Most likely node.photos is not initialized because the initialization happens in oauth2Client which is only called when the credentials are expired at the time we call oauth2Client.refreshAccessToken(which is called at start and every 45 minutes).

So if we keep some patience it might automatically resolve itselves when refreshing the toking after expiration.

janvda commented 4 years ago

When initalizing node.photos = new Photos(node.config.credentials.accessToken); we know get following error:

15.12.19 16:35:57 (+0100)  node-red  15 Dec 15:35:57 - [warn] [google:google photos api] node.on('input'):[object Object]
15.12.19 16:35:57 (+0100)  node-red  15 Dec 15:35:57 - [warn] [google:google photos api] get_albums_list ...
15.12.19 16:35:57 (+0100)  node-red  15 Dec 15:35:57 - [warn] [google:google photos api] ... end node.on()
15.12.19 16:35:58 (+0100)  node-red  15 Dec 15:35:58 - [error] [google:google photos api] StatusCodeError: 401 - {"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}}
janvda commented 4 years ago

I have same problem on macbook installation - so it looks like the google api is recently behaving differently so that tokens are no longer refreshed.

janvda commented 4 years ago
npm install --save-exact google-auth-library@5.6.1
janvda commented 4 years ago

it is working again on macbook although I didn't change anything. macbook has the following configuration:

bash-5.0$ Jans-MBP:~ jan$ npm -v
6.11.3
Welcome to Node-RED
===================
16 Dec 07:46:55 - [info] Node-RED version: v1.0.3
16 Dec 07:46:55 - [info] Node.js  version: v10.17.0
16 Dec 07:46:55 - [info] Linux 4.9.184-linuxkit x64 LE
16 Dec 07:46:56 - [info] Loading palette nodes
16 Dec 07:47:04 - [info] Dashboard version 2.19.2 started at /ui
bash-5.0$ npm list | grep google
+-- node-red-contrib-google-photos@0.0.1 -> /data/node-red-contrib-google-photos
| +-- googleapis@45.0.0
| | +-- google-auth-library@5.7.0
| | | | +-- google-p12-pem@2.0.3
| | `-- googleapis-common@3.2.0
| |   +-- google-auth-library@5.7.0 deduped
| `-- googlephotos@0.2.5
janvda commented 4 years ago

The configuration of balena having the problem:

16.12.19 08:32:36 (+0100)  node-red  Welcome to Node-RED
16.12.19 08:32:36 (+0100)  node-red  ===================
16.12.19 08:32:36 (+0100)  node-red  
16.12.19 08:32:36 (+0100)  node-red  16 Dec 07:32:36 - [info] Node-RED version: v1.0.2
16.12.19 08:32:36 (+0100)  node-red  16 Dec 07:32:36 - [info] Node.js  version: v12.11.1
16.12.19 08:32:36 (+0100)  node-red  16 Dec 07:32:36 - [info] Linux 4.14.98 arm LE
bash-4.4$ npm -v
6.11.3
bash-4.4$ npm list | grep google
+-- google-auth-library@5.6.1
| | +-- google-p12-pem@2.0.3
+-- node-red-contrib-google-photos@0.0.1 (github:janvda/node-red-contrib-google-photos#ad4d710fd3674725c9e45d83fb888db9fcf930e3)
| +-- googleapis@45.0.0
| | +-- google-auth-library@5.6.1 deduped
| | `-- googleapis-common@3.2.0
| |   +-- google-auth-library@5.6.1 deduped
| `-- googlephotos@0.2.5
bash-4.4$ 
janvda commented 4 years ago

installed google-auth-library@5.7.0 on pi3two

bash-4.4$ npm list | grep google
+-- google-auth-library@5.7.0
| | +-- google-p12-pem@2.0.3
+-- node-red-contrib-google-photos@0.0.1 (github:janvda/node-red-contrib-google-photos#ad4d710fd3674725c9e45d83fb888db9fcf930e3)
| +-- googleapis@45.0.0
| | +-- google-auth-library@5.7.0 deduped
| | `-- googleapis-common@3.2.0
| |   +-- google-auth-library@5.7.0 deduped
| `-- googlephotos@0.2.5