在Twitter上与查询字符串共享URL [英] Sharing a URL with a query string on Twitter
问题描述
我正在尝试在电子邮件中放置一个Twitter共享链接.因为这是一封电子邮件,所以我不能依靠JavaScript,而必须使用自己构建"鸣叫按钮.
I'm trying to put a Twitter share link in an email. Because this is in an email I can't rely on JavaScript, and have to use the "Build Your Own" Tweet button.
例如,共享指向Google的链接:
For example, sharing a link to Google:
<a href="http://www.twitter.com/share?url=http://www.google.com/>Tweet</a>
这很好.我遇到的问题是URL有查询字符串时.
This works fine. The problem I'm having is when the URL has a query string.
<a href="http://www.twitter.com/share?url=http://mysite.org/foo.htm?bar=123&baz=456">Tweet</a>
带有查询字符串的URL会混淆Twitter的URL缩短服务t.co.我已经尝试过以各种方式对URL进行编码,并且无法正常工作.我最近得到的就是这样做.
URLs with query strings confuse Twitter's URL shortening service, t.co. I've tried URL encoding this in various ways and cannot get anything to work. The closest I have gotten is by doing this.
<a href="http://www.twitter.com/share?url=http://mysite.org/foo.htm%3Fbar%3D123%26baz%3D456">Tweet</a>
在这里,我仅对查询字符串进行了编码.当我这样做时,t.co成功地缩短了URL,但是按照缩短的链接,它将带您到编码的URL.我在地址栏中看到http://mysite.org/foo.htm%3Fbar%3D123%26baz%3D456
,并在浏览器中得到以下错误
Here I've encoded only the query string. When I do this, t.co successfully shortens the URL, but upon following the shortened link, it takes you to the encoded URL. I see http://mysite.org/foo.htm%3Fbar%3D123%26baz%3D456
in the address bar, and get the following error in the browser
未找到
在此服务器上找不到请求的URL/foo.htm?bar=123&baz=456.
The requested URL /foo.htm?bar=123&baz=456 was not found on this server.
我不知道如何解决这个问题.
I'm at a loss as to how to solve this problem.
回复:onteria _
Re: onteria_
我尝试对整个URL进行编码.当我这样做时,Tweet中不会显示URL.
I've tried encoding the entire URL. When I do that no URL shows up in the Tweet.
推荐答案
这可以通过使用https://twitter.com/intent/tweet
而不是http://www.twitter.com/share
来解决.使用intent/tweet
函数,您只需对整个URL进行URL编码,就可以像超级按钮一样工作.
This can be solved by using https://twitter.com/intent/tweet
instead of http://www.twitter.com/share
. Using the intent/tweet
function, you simply URL encode your entire URL and it works like a charm.
https://dev.twitter.com/web/intents
这篇关于在Twitter上与查询字符串共享URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!