在 Twitter 上共享带有查询字符串的 URL [英] Sharing a URL with a query string on Twitter

查看:20
本文介绍了在 Twitter 上共享带有查询字符串的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在电子邮件中添加 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 进行编码.当我这样做时,推文中不会显示任何网址.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆