我使用下面的代码来显示一个已经填充了消息的 Twitter 框的页面:
<a href="http://www.twitter.com/share.php?url=http://myurl.com&text=myMessage" target="_blank">Click me</a>
然而,在页面上,我在 Twitter 框中得到这个:
myMessage/
注意尾部斜杠。任何想法如何解决这个问题?
We have found a workaround for this,where you add the source = webclient parameter,crucially,to the END of the twitter address.When you do this,Twitter no longer adds the training slash.However,given how Twitter like to change their formats and codes around,there 's
例如
<a href="https://twitter.com/intent/tweet?text=http://www.rsc.org%2FEducation%2FEiC%2Fissues%2F2013January%2F50th%2Delement%2Dtin%2Easp&source=webclient" target="_blank">Twitter this</a>
不,解决方案更简单。URL 编码你的 URL:
https://twitter.com/intent/tweet?text=myMessage&url=http%3A%2F%2Fmyurl.com
添加一个尾部斜杠到你的 URL,应该消失。它为我工作。
从这个更改 URL:
http://www.twitter.com/share?url=http://myurl.com&text=myMessage
为此:
http://www.twitter.com/share?url=http://myurl.com/&text=myMessage

正如 Twitter 文档声称(twitter original reference):
具有 HTTP 或 HTTPS 方案的完全限定URL,URL 编码。
完全限定的 URL 需要有尾部斜杠。从相同的文档:
示例值:http:% 3A% 2F% 2Fexample.com% 2F
请注意,该示例的末尾有%2F
,这是 HTML 编码的/
字符。Twitter 尝试通过自动附加/
来创建正确的 URL。
将您的url
GET 参数设置为http://myurl.com/
以摆脱尾部斜杠
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(79条)