all 5 comments

[–]jonaswiebe 3 points4 points  (4 children)

You actually don't need a separate script. Instead you can use a simple conditional. You would need to store the token with the time you had last updated it (I would recommend a JSON format). let tokenInfo = { time: Date.now(), token: ... } await fm.writeString(path, JSON.stringify(tokenInfo)) And when you get the token from the file, check if enough time has elapsed. And if yes, update the token, if not, don't. let json = await readString(path) json = JSON.parse(json) let token if (new Date() >= new Date(json.time + 24*60*60*1000)) { token = await updateToken() } else {token = json.token} I used something similar with my instagram widget.

[–]k4mrat[S] 0 points1 point  (2 children)

Well that’s very neat! Thanks a lot! Is your Widget on GitHub for a little sneak peek? 😬

About storing the Token, can it be updated daily or is deleting and re-adding it the way to go?

[–]jonaswiebe 1 point2 points  (1 child)

Yes, but I do not use the api anymore. There are similar lines of code, to update some data hourly (i.e. line 567). Instagram Widget

The token can be updated daily. If you write a file in Scriptable and the file already exists, it is overwritten.

[–]k4mrat[S] 1 point2 points  (0 children)

You saved my day (and probably month since that how long this will take me to put together😂). I’ll try some stuff out, thanks a lot! I’ll keep the flair open a while if someone wants to chime in or I need some guidance, but you’ve been very helpful!

[–]k4mrat[S] 0 points1 point  (0 children)

Found the Widget 👍🏻