I am currently developing a JavaScript script to work alongside my C++ application for sending direct messages to users. The script is responsible for constructing the request that I send out. However, whenever I make a request, I keep getting errors like "Incorrect signature" or "can not authenticate you." Can anyone spot any mistakes or missing elements in what I'm doing? I am actively investigating this issue. Thank you in advance.
Here is a snippet of the JavaScript code:
var nDate = new Date();
var epoch = nDate.getTime();
var nonce = "";
nonce = Base64.encode(epoch + randomString());
var Parameters = [
"oauth_consumerkey=" + sConsumerKey,
"oauth_nonce=" + nonce,
"oauth_signature_method=HMAC-SHA1",
"oauth_timestamp=" + epoch,
"oauth_token=" + sAccessToken,
"oauth_version=1.0",
"text=" + sText,
"user=" + sUser
];
var SortedParameters = Parameters.sort();
var joinParameters = SortedParameters.join("&");
var encodeParameters = escape(joinParameters);
signature_base_string = escape("POST&" + NormalizedURL + "&" + encodeParameters);
signature_key = sConsumerSecret + "&" + sAccessSecret;
signature = Base64.encode(hmacsha1(signature_base_string, signature_key));
sAuthHeader = "
OAuth realm=,
oauth_nonce=" + nonce + ",
oauth_timestamp=" + epoch + ",
oauth_consumer_key=" + sConsumerKey + ",
oauth_signature_method=HMAC-SHA1,
oauth_version=1.0,
oauth_signature=" + signature + ",
oauth_token=" + sAccessToken + ",
text=" + sText;
goNVOut.Set("Header.Authorization: ", sAuthHeader);