I’ve cobbled together some code like an illiterate pig farmer, but I’m having trouble with “function not defined” and I suspect it’s happening because of variable scope.
The likely reasons:
I don’t know how to properly insert a variable inside a URL string to add a header.
Also probably not correct syntax on adding a variable I would like to represent an entire URL to an API fetch call.
And there’s probably an easier way to define the “screen_name” variable in the fetch function without this ‘cut and paste’ approach. Open to a better way like Eddie Vedder…
Le Code:
<!DOCTYPE html>
<html>
<body style="text-align:center;">
<h1 style="color:Black;">
Hidden Portal to the Mint
</h1>
<h2>Are you one of the Forces?</h2>
<p>
Check Twitter Username Below
</p>
<input type="text" id="twiText" value="@WhoDis?">
<button type="button" id=twiButt onclick="twiFunc(); hookUP(); apiSend();">Send</button>
<p id="demo"></p>
<script>
// Two functions - twiFunc and apiSend.
//twiFunc converts the text input to new variable twiHan
// and appends the API URL accordingly
//variable urlString created adding twiHan between urlBEG and urlEnd to the Twitter API fetch url.
var urlBEG = "https://api.twitter.com/1.1/friendships/lookup.json?screen_name=”;
var twiHan = “”;
var urlEND = “&oauth_consumer_key=...&oauth_token=...-...&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1661985353&oauth_nonce=agFimxv5MRw&oauth_version=1.0&oauth_signature=JryUeZuz0GF9OxY3PMPlR2RdXtA%3D", requestOptions)”;
var urlString = urlBEG + urlBEGG + twiHan + urlEND;
function twiFunc() {
twiHan = document.getElementById("twiText").value;
document.getElementById("demo").innerHTML = twiHan;
}
function apiSend() {
var myHeaders = new Headers();
myHeaders.append("Cookie", "guest_id=v1%3A166156211780027632");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("urlString", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
var followed_by = response["connections"].includes("followed_by");
console.log(followed_by);
console.log(urlString);
</script>
</body>
</html>
Any pointers appreciated, feels like I’m zeroing in on my functionality!
