I have been working on an app to communicate with the Particle API, but the API requires some of the text information to be Base 64 Encoded for it to interpret it. How is this possible with Thunkable X?
I have a functional version of my app running with Thunkable Classic, as there is an extension that directly encodes any string to base64, but I badly need the app to have cross platform support.
Any help would be greatly appreciated! Thanks,
Isaac
Do I have to use API bloks to use this code or could I use this bloks without linking any API?
I’d prefer not using and manage external API but decode and encode inside the app.
If your base64 value is static, you could hard code it in the app. The API I’m using is - it wants a client ID and secret encoded, so I just did it once with an online encoder and pasted the value into an app variable.
If that value is dynamic, then you need some way to get it. I have a little piece of JavaScript that takes the string to encode and passes it back encoded. It only takes the web viewer block to use it, as long as you have a webpage to put the JavaScript on. Let me know if you want to see the blocks and JS code.
Here’s the JS:
<script>
//Use this if you want to pass in 'code' as part of the URL string (yourdomain.com?code=CODESTRINGHERE)
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const my_code = urlParams.get('code')
// currently I just pass back the code that was passed in, but mash it up with the second bit of code below, and you've got a base64 encoder/
ThunkableWebviewerExtension.postMessage(my_code);
//alternately, use the code below to take a message in, encode it, and pass it back.
// when we get a message from the app, display it on the page
//ThunkableWebviewerExtension.receiveMessage(function(message) {
// Do something with your message
// const reply_message = 'base64,' + btoa(message);
//ThunkableWebviewerExtension.postMessage(reply_message);
//});
</script>