Looking to create a single function Twitter bot that sits on a webpage, takes a single text input, appends a URL, and returns a single data point – “is user following Account X?” Account X is a constant. Using Javascript. Building on Wix.com’s VeloAPI so some code might look different,

Incoming text input gets turned into variable twiHan (short for Twitter Handle.)

Wix HTML:

var twiHan = “initial”;

export function button3_click(event) {
twiHan = $w(‘#input2’).value;
console.log(twiHan);

Q: How do I overwrite the first secret’s value with this input text?

This function in the .jsw returns the value of the first secret.

export function getFirstSecretValue() {

return wixSecretsBackend.listSecretInfo()
.then((secrets) => {
return wixSecretsBackend.getSecret(secrets[0].name);
})

.catch((error) => {
console.error(error);
});
}

This function (currently minus Authorization code) will pull the first secret’s value, input it into the URL, perform the getJSON operation, and return something (at this point a Bad Authentication error, but server contact is happening, I’ll fill in the headers after I solve this basic code question. CORS is supported because Wix.com/Velo API I’m stuck using.

export async function getSecreto() {

try {
const secret = await getSecret(‘UserName’);
return getJSON(https://api.twitter.com/1.1/friendships/lookup.json?screen_name=${secret}
);

} catch (err) {
console.error(err);
}
}

The update/overwrite function could come before the getJSON function at the click event, but how do I update or overwrite the first Secret’s value with the variable value? I’ve been through the wix-secrets-backend API docs and it’s still not quite making sense to me.

And if you’re wondering about CORS - the Wix Velo API supports calls from backend web modules.

I’m sure I’ll have more question about Authentication but for now I just need to figure this part out. Thanks!

The title of the post made it look like you want to use code to regenerate a Twitter API secret via the API, but at the moment this looks more like a general question of how you take the output from one HTML page form and plug it into another, rather than something specific to the Twitter API?

Note that the Twitter does not support CORS, so you cannot call it directly from a web browser - you need to use a server-side proxy - this may be why you hit a Bad Auth error, although you would usually see some kind of CORS error in the client side code.

1 Like

When you use the term “regenerate” - I don’t want to regenerate API keys or similar.

CORS is supported and I can call from backend Javascript - because I’m using the Velo code associated with Wix.com. The reason I got a Bad Authentication error is that I didn’t send any authorization headers. I’m not to that point in the code yet. But that code I posted above works - it calls the API and returns information. And I can call that function from the .jsw file.

But yes, I am trying to use code to rewrite or overwrite the Key, using text information input by a user. I’m looking for basic coding information here about passing variables.