【问题标题】:ASPTwitter library fails when using special characters使用特殊字符时 ASPTwitter 库失败
【发布时间】:2013-10-17 07:15:37
【问题描述】:

我正在尝试更新我的工作当前使用的旧 ASP 经典 Twitter 程序以使用新的 OAUTH。我不是 ASP 程序员,但我设法找到了 Tim Acheson 在http://www.timacheson.com/Blog/2013/jun/asptwitter 在线发布的 ASPTwitter 库

一切正常,因为我们有自己的代码搜索我们的数据库并将构建的字符串传递给 ASPTwitter 代码以发布推文。

问题是它会失败

{"errors":[{"message":"Could not authenticate you","code":32}]}

如果有这么多的“。”,则会出现错误消息。字符串中的句点。除了字母和数字之外的每个可能的特殊字符都会导致失败。

我们有很多帖子会包含各种符号和 URL。

我已经搜索了所有内容,但无法找到解决方案。蒂姆网站上的评论提到了它,但还没有解决方案。这里的每个人都非常有帮助,所以我希望有人可以提供解决方案。

我无法发布代码,因为大约有 6 个文件,我不知道是哪个文件导致了问题。

非常感谢您的帮助!

编辑:

这是出现问题的300+行文件的一个块,我希望在这里也能找到原因。

' Gets bearer token for application-only authentication from Twitter API 1.1.
' Application-user authentication: https://dev.twitter.com/docs/auth/using-oauth
' and: https://dev.twitter.com/docs/auth/authorizing-request
' API endpoint statuses/update (post a tweet): https://dev.twitter.com/docs/api/1.1/post/statuses/update
Private Function UpdateStatusJSON(sStatus)

    Dim sURL : sURL = API_BASE_URL + "/1.1/statuses/update.json"

    Dim oXmlHttp: Set oXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP") 

    oXmlHttp.open "POST", sURL, False



    sStatus = "this is from the ASPTwitter dot asp file"


    oXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"
    oXmlHttp.setRequestHeader "User-Agent", "emiratesjobpost.com"
    oXmlHttp.setRequestHeader "Authorization", "OAuth " & GetOAuthHeader(sURL, sStatus)

    oXmlHttp.send "status=" & Server.URLEncode(sStatus) ' Encoded spaces as + in request body.

    UpdateStatusJSON = oXmlHttp.responseText

    Set oXmlHttp = Nothing

    REM: A JSON viewer can be useful here: http://www.jsoneditoronline.org/
    ' To fix error message "Read-only application cannot POST" go to your application's "Application Type" settings at dev.twitter.com/apps and set "Access" to "Read and Write".
    ' After changing access to read/write you must click the button to generate new auth tokens and then use those.
    Response.Write "<textarea cols=""100"" rows=""3"" >" & UpdateStatusJSON & "</textarea>" : Response.Flush()

End Function

如果我将“点”替换为“。”在“sStatus”行中,它会中断

【问题讨论】:

  • 如果您改用oXmlHttp.send "status=" &amp; sStatus,它会中断吗?即:删除urlencode?​​span>

标签: api twitter asp-classic vbscript tweets


【解决方案1】:

您的网页是否使用 UTF-8 编码?在记事本中打开它们,从文件菜单中选择另存为,如果选择了ansi编码,则将其更改为UTF-8。

查看此链接了解更多您可以做的事情

http://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx

【讨论】:

  • 我希望这能解决这个问题,但我确保每个 asp 文件都是 UTF-8 并且我仍然遇到问题。如果我在消息中包含句点,它会报告它无法进行身份验证,取出句点并发布。我编辑了第一篇文章,至少包含了错误发生位置的代码,希望对您有所帮助。
猜你喜欢
  • 2016-10-08
  • 2012-11-20
  • 1970-01-01
  • 1970-01-01
  • 2015-09-14
  • 2021-02-04
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
相关资源
最近更新 更多