Some (not all) punctuation in a tweet causes API error 32 “Could not authenticate you” Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!URL Encoding using C#Percentage Encoding of special characters before sending it in the URLTwitter Error Could not post TweetCould not authenticate with OAuth error when passing parameters Twitter API“errors”:[“message”:“Could not authenticate you”,“code”:32]Tweet : Getting error 32 Could not authenticate youTwitter API - GET search/tweets for hashtag returns “Could not authenticate you”Could not authenticate you twitterTwitter API 1.1 Could not authenticate you 2Twitter API Error 32 Could not authenticate youTwitter,“Could not authenticate you” ErrorTwitter API not returning all tweets

What order were files/directories output in dir?

Tips to organize LaTeX presentations for a semester

Was Kant an Intuitionist about mathematical objects?

Tannaka duality for semisimple groups

Why does electrolysis of aqueous concentrated sodium bromide produce bromine at the anode?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

Why complex landing gears are used instead of simple,reliability and light weight muscle wire or shape memory alloys?

What initially awakened the Balrog?

Test print coming out spongy

How can I save and copy a screenhot at the same time?

White walkers, cemeteries and wights

Relating to the President and obstruction, were Mueller's conclusions preordained?

Does the Mueller report show a conspiracy between Russia and the Trump Campaign?

Putting class ranking in CV, but against dept guidelines

After Sam didn't return home in the end, were he and Al still friends?

How does light 'choose' between wave and particle behaviour?

AppleTVs create a chatty alternate WiFi network

My mentor says to set image to Fine instead of RAW — how is this different from JPG?

what is the log of the PDF for a Normal Distribution?

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

Where is the Next Backup Size entry on iOS 12?

What does 丫 mean? 丫是什么意思?

Delete free apps from library

How can a team of shapeshifters communicate?



Some (not all) punctuation in a tweet causes API error 32 “Could not authenticate you”



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!URL Encoding using C#Percentage Encoding of special characters before sending it in the URLTwitter Error Could not post TweetCould not authenticate with OAuth error when passing parameters Twitter API“errors”:[“message”:“Could not authenticate you”,“code”:32]Tweet : Getting error 32 Could not authenticate youTwitter API - GET search/tweets for hashtag returns “Could not authenticate you”Could not authenticate you twitterTwitter API 1.1 Could not authenticate you 2Twitter API Error 32 Could not authenticate youTwitter,“Could not authenticate you” ErrorTwitter API not returning all tweets



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I rejoiced when I finally got some ASP.NET code talking to Twitter's API, and it performed perfectly when testing, creating tweets of any length on my account, mentioning @usernames, and even tweeting 10 times a minute to the same account.



But now I am getting HTTP status code 401 and this JSON back:
"errors":["code":32, "message":"Could not authenticate you."]



The errors almost appeared random, until I noticed something. It seems I never used punctuation in any of my previous tests! Now, tweets with apostrophes, brackets and exclamation marks are rejected - yet commas, hyphens and question marks are fine.



The first line of this section must be my problem area:



Dim postBody = "media_ids=" & TwitterMediaID & "&status=" & Uri.EscapeDataString(TextOfTheTweet)
System.Net.ServicePointManager.Expect100Continue = False
Dim request As System.Net.HttpWebRequest = System.Net.WebRequest.Create(TwitterStatusPostURL)
request.Headers.Add("Authorization", OAuthSignature)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"


I guess Uri.EscapeDataString() is the wrong choice of encoding, though I am very grateful to the original author for this code because I would be nowhere without them!



This function takes in Apotrophe' exclamation! brackets() question? fullstop. comma, colon: semicolon; hyphen- and returns Apotrophe'%20exclamation!%20brackets()%20question%3F%20fullstop.%20comma%2C%20colon%3A%20semicolon%3B%20hyphen- which is clearly not what Twitter wants to see (or rather, this is something to do with OAuth?).



According to the wonderful table in this SO question there is nothing that encodes an exclamation mark?!



I should be able to find a better function to use, by myself, but I'd love to hear exactly what the problem was here, and have reassurance that I understand which encoding functions are right for which job. This also needs to be documented for future punctuation-addled programmers.



So the question can be summarised as: Why is this function not the right choice, and what should we use? Thanks.










share|improve this question
























  • This is due to encoding and OAuth. You need to encode certain values. Check out this page for more information

    – Andy Piper
    Mar 22 at 12:59

















0















I rejoiced when I finally got some ASP.NET code talking to Twitter's API, and it performed perfectly when testing, creating tweets of any length on my account, mentioning @usernames, and even tweeting 10 times a minute to the same account.



But now I am getting HTTP status code 401 and this JSON back:
"errors":["code":32, "message":"Could not authenticate you."]



The errors almost appeared random, until I noticed something. It seems I never used punctuation in any of my previous tests! Now, tweets with apostrophes, brackets and exclamation marks are rejected - yet commas, hyphens and question marks are fine.



The first line of this section must be my problem area:



Dim postBody = "media_ids=" & TwitterMediaID & "&status=" & Uri.EscapeDataString(TextOfTheTweet)
System.Net.ServicePointManager.Expect100Continue = False
Dim request As System.Net.HttpWebRequest = System.Net.WebRequest.Create(TwitterStatusPostURL)
request.Headers.Add("Authorization", OAuthSignature)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"


I guess Uri.EscapeDataString() is the wrong choice of encoding, though I am very grateful to the original author for this code because I would be nowhere without them!



This function takes in Apotrophe' exclamation! brackets() question? fullstop. comma, colon: semicolon; hyphen- and returns Apotrophe'%20exclamation!%20brackets()%20question%3F%20fullstop.%20comma%2C%20colon%3A%20semicolon%3B%20hyphen- which is clearly not what Twitter wants to see (or rather, this is something to do with OAuth?).



According to the wonderful table in this SO question there is nothing that encodes an exclamation mark?!



I should be able to find a better function to use, by myself, but I'd love to hear exactly what the problem was here, and have reassurance that I understand which encoding functions are right for which job. This also needs to be documented for future punctuation-addled programmers.



So the question can be summarised as: Why is this function not the right choice, and what should we use? Thanks.










share|improve this question
























  • This is due to encoding and OAuth. You need to encode certain values. Check out this page for more information

    – Andy Piper
    Mar 22 at 12:59













0












0








0








I rejoiced when I finally got some ASP.NET code talking to Twitter's API, and it performed perfectly when testing, creating tweets of any length on my account, mentioning @usernames, and even tweeting 10 times a minute to the same account.



But now I am getting HTTP status code 401 and this JSON back:
"errors":["code":32, "message":"Could not authenticate you."]



The errors almost appeared random, until I noticed something. It seems I never used punctuation in any of my previous tests! Now, tweets with apostrophes, brackets and exclamation marks are rejected - yet commas, hyphens and question marks are fine.



The first line of this section must be my problem area:



Dim postBody = "media_ids=" & TwitterMediaID & "&status=" & Uri.EscapeDataString(TextOfTheTweet)
System.Net.ServicePointManager.Expect100Continue = False
Dim request As System.Net.HttpWebRequest = System.Net.WebRequest.Create(TwitterStatusPostURL)
request.Headers.Add("Authorization", OAuthSignature)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"


I guess Uri.EscapeDataString() is the wrong choice of encoding, though I am very grateful to the original author for this code because I would be nowhere without them!



This function takes in Apotrophe' exclamation! brackets() question? fullstop. comma, colon: semicolon; hyphen- and returns Apotrophe'%20exclamation!%20brackets()%20question%3F%20fullstop.%20comma%2C%20colon%3A%20semicolon%3B%20hyphen- which is clearly not what Twitter wants to see (or rather, this is something to do with OAuth?).



According to the wonderful table in this SO question there is nothing that encodes an exclamation mark?!



I should be able to find a better function to use, by myself, but I'd love to hear exactly what the problem was here, and have reassurance that I understand which encoding functions are right for which job. This also needs to be documented for future punctuation-addled programmers.



So the question can be summarised as: Why is this function not the right choice, and what should we use? Thanks.










share|improve this question
















I rejoiced when I finally got some ASP.NET code talking to Twitter's API, and it performed perfectly when testing, creating tweets of any length on my account, mentioning @usernames, and even tweeting 10 times a minute to the same account.



But now I am getting HTTP status code 401 and this JSON back:
"errors":["code":32, "message":"Could not authenticate you."]



The errors almost appeared random, until I noticed something. It seems I never used punctuation in any of my previous tests! Now, tweets with apostrophes, brackets and exclamation marks are rejected - yet commas, hyphens and question marks are fine.



The first line of this section must be my problem area:



Dim postBody = "media_ids=" & TwitterMediaID & "&status=" & Uri.EscapeDataString(TextOfTheTweet)
System.Net.ServicePointManager.Expect100Continue = False
Dim request As System.Net.HttpWebRequest = System.Net.WebRequest.Create(TwitterStatusPostURL)
request.Headers.Add("Authorization", OAuthSignature)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"


I guess Uri.EscapeDataString() is the wrong choice of encoding, though I am very grateful to the original author for this code because I would be nowhere without them!



This function takes in Apotrophe' exclamation! brackets() question? fullstop. comma, colon: semicolon; hyphen- and returns Apotrophe'%20exclamation!%20brackets()%20question%3F%20fullstop.%20comma%2C%20colon%3A%20semicolon%3B%20hyphen- which is clearly not what Twitter wants to see (or rather, this is something to do with OAuth?).



According to the wonderful table in this SO question there is nothing that encodes an exclamation mark?!



I should be able to find a better function to use, by myself, but I'd love to hear exactly what the problem was here, and have reassurance that I understand which encoding functions are right for which job. This also needs to be documented for future punctuation-addled programmers.



So the question can be summarised as: Why is this function not the right choice, and what should we use? Thanks.







.net twitter twitter-oauth urlencode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 13:00







Magnus Smith

















asked Mar 22 at 11:51









Magnus SmithMagnus Smith

3,56673357




3,56673357












  • This is due to encoding and OAuth. You need to encode certain values. Check out this page for more information

    – Andy Piper
    Mar 22 at 12:59

















  • This is due to encoding and OAuth. You need to encode certain values. Check out this page for more information

    – Andy Piper
    Mar 22 at 12:59
















This is due to encoding and OAuth. You need to encode certain values. Check out this page for more information

– Andy Piper
Mar 22 at 12:59





This is due to encoding and OAuth. You need to encode certain values. Check out this page for more information

– Andy Piper
Mar 22 at 12:59












1 Answer
1






active

oldest

votes


















0














Twitter API documentation (as of March 2019) says I must use RFC 3986.



It seems the older version of dotNET that I am using doesn't support RFC 3986 fully within Uri.EscapeDataString() and I would need dotNET v4.5 or above to solve that issue.



This answer to a similar question says I can just make up the four missing punctuation elements myself with this one-liner:



Regex.Replace(Uri.EscapeDataString(s), "[!*'()]", Function(m) Uri.HexEscape(Convert.ToChar(m.Value(0).ToString())))


Personally I feel comfortable with a more readable version:



Uri.EscapeDataString(s).Replace("!", "%21").Replace("'", "%27").Replace("(", "%28").Replace(")", "%29")





share|improve this answer























  • I've just discovered that my second code snippet is missing the asterisk. There are five punctuation symbols, not four!

    – Magnus Smith
    Apr 15 at 10:50











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299007%2fsome-not-all-punctuation-in-a-tweet-causes-api-error-32-could-not-authenticat%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Twitter API documentation (as of March 2019) says I must use RFC 3986.



It seems the older version of dotNET that I am using doesn't support RFC 3986 fully within Uri.EscapeDataString() and I would need dotNET v4.5 or above to solve that issue.



This answer to a similar question says I can just make up the four missing punctuation elements myself with this one-liner:



Regex.Replace(Uri.EscapeDataString(s), "[!*'()]", Function(m) Uri.HexEscape(Convert.ToChar(m.Value(0).ToString())))


Personally I feel comfortable with a more readable version:



Uri.EscapeDataString(s).Replace("!", "%21").Replace("'", "%27").Replace("(", "%28").Replace(")", "%29")





share|improve this answer























  • I've just discovered that my second code snippet is missing the asterisk. There are five punctuation symbols, not four!

    – Magnus Smith
    Apr 15 at 10:50















0














Twitter API documentation (as of March 2019) says I must use RFC 3986.



It seems the older version of dotNET that I am using doesn't support RFC 3986 fully within Uri.EscapeDataString() and I would need dotNET v4.5 or above to solve that issue.



This answer to a similar question says I can just make up the four missing punctuation elements myself with this one-liner:



Regex.Replace(Uri.EscapeDataString(s), "[!*'()]", Function(m) Uri.HexEscape(Convert.ToChar(m.Value(0).ToString())))


Personally I feel comfortable with a more readable version:



Uri.EscapeDataString(s).Replace("!", "%21").Replace("'", "%27").Replace("(", "%28").Replace(")", "%29")





share|improve this answer























  • I've just discovered that my second code snippet is missing the asterisk. There are five punctuation symbols, not four!

    – Magnus Smith
    Apr 15 at 10:50













0












0








0







Twitter API documentation (as of March 2019) says I must use RFC 3986.



It seems the older version of dotNET that I am using doesn't support RFC 3986 fully within Uri.EscapeDataString() and I would need dotNET v4.5 or above to solve that issue.



This answer to a similar question says I can just make up the four missing punctuation elements myself with this one-liner:



Regex.Replace(Uri.EscapeDataString(s), "[!*'()]", Function(m) Uri.HexEscape(Convert.ToChar(m.Value(0).ToString())))


Personally I feel comfortable with a more readable version:



Uri.EscapeDataString(s).Replace("!", "%21").Replace("'", "%27").Replace("(", "%28").Replace(")", "%29")





share|improve this answer













Twitter API documentation (as of March 2019) says I must use RFC 3986.



It seems the older version of dotNET that I am using doesn't support RFC 3986 fully within Uri.EscapeDataString() and I would need dotNET v4.5 or above to solve that issue.



This answer to a similar question says I can just make up the four missing punctuation elements myself with this one-liner:



Regex.Replace(Uri.EscapeDataString(s), "[!*'()]", Function(m) Uri.HexEscape(Convert.ToChar(m.Value(0).ToString())))


Personally I feel comfortable with a more readable version:



Uri.EscapeDataString(s).Replace("!", "%21").Replace("'", "%27").Replace("(", "%28").Replace(")", "%29")






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 22 at 20:26









Magnus SmithMagnus Smith

3,56673357




3,56673357












  • I've just discovered that my second code snippet is missing the asterisk. There are five punctuation symbols, not four!

    – Magnus Smith
    Apr 15 at 10:50

















  • I've just discovered that my second code snippet is missing the asterisk. There are five punctuation symbols, not four!

    – Magnus Smith
    Apr 15 at 10:50
















I've just discovered that my second code snippet is missing the asterisk. There are five punctuation symbols, not four!

– Magnus Smith
Apr 15 at 10:50





I've just discovered that my second code snippet is missing the asterisk. There are five punctuation symbols, not four!

– Magnus Smith
Apr 15 at 10:50



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299007%2fsome-not-all-punctuation-in-a-tweet-causes-api-error-32-could-not-authenticat%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript