Facebook 和 Twitter 共享移动网络
是否有用于在移动设备上分享到 Facebook 和 Twitter 的特殊 URL? 或者它们与网站上的相同吗?
用于
<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
<a href="javascript:return false;" rel="nofollow" onclick="window.open('https://twitter.com/share?text=sometext&url=someurl', 'Twitter', 'toolbar=0,status=0,width=626,height=436')">Twitter</a>
Twitter 和
<script>
function fbs_click()
{
u='www.something';
t='title';
window.open('http://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
return false;
}
</script>
<a rel="nofollow" href="http://www.facebook.com/sharer/sharer.php?u=someurl" onclick="return fbs_click()" target="_blank" class="">Facebook</a>
Facebook。
Is there a special url for sharing to Facebook and Twitter for mobile?
Or are they the same as those from websites?
Using
<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
<a href="javascript:return false;" rel="nofollow" onclick="window.open('https://twitter.com/share?text=sometext&url=someurl', 'Twitter', 'toolbar=0,status=0,width=626,height=436')">Twitter</a>
for Twitter and
<script>
function fbs_click()
{
u='www.something';
t='title';
window.open('http://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
return false;
}
</script>
<a rel="nofollow" href="http://www.facebook.com/sharer/sharer.php?u=someurl" onclick="return fbs_click()" target="_blank" class="">Facebook</a>
for Facebook.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的共享实现应该是相同的,并且只要您的移动用户拥有能够渲染 JavaScript 的设备,就应该可以工作。否则,您可以使用每个平台的 API url 在链接内共享,唯一的问题是回调将它们重定向到 Twitter 或 Facebook,并且它们必须手动返回到您的网站。链接如下:
Facebook 分享:
例如:
Twitter 更新状态:
Your sharing implementation should be the same and should work so long as your mobile users have devices capable or rendering JavaScript. Otherwise you can use each platforms' API url to share inside a link, the only problem is the callback redirects them either to Twitter or Facebook and they'll have to manually return to your site. The links are as below:
Sharing on Facebook:
For example:
Updating status on Twitter:
关于 Simpleton 答案的一些注释。
http://m.facebook.com/sharer.php 网址可能不是您想要的。您在 u 查询参数中提供的网站需要在页面中包含一些标签才能共享
页面非常有趣。只要尝试在其中添加除 Google 之外的另一个 URL 即可明白我的意思。我从来没有真正弄清楚它在网站页面中寻找什么,以便在共享页面中显示任何有用的内容。我没有找到任何方法来提供有关您正在共享的网站的额外信息。
据我所知,facebook 不再读取 t 查询参数
据我
我发现 Facebook feed 对话框是更好的共享替代方案(https://developers.facebook.com/docs/reference/dialogs/feed/)。请参阅该页面底部的示例,了解您可以共享的信息。将该示例 URL 粘贴到浏览器中以查看其外观。您可以尝试使用这些参数来查看每个参数在帖子中控制的内容。例如,如果您不提供标题参数,则似乎会在其位置使用链接参数的基本 URL。要使用提要对话框方法,您需要在 Facebook 中注册您的应用程序以获取需要包含在提要对话框 URL 中的 app_id。您还可以将您的应用程序与网站 URL 相关联,您也可以在摘要对话框 URL 中使用该网站 URL。如果您希望 Facebook 为您提供适合移动设备的页面,请将 &display=touch 附加到提要对话框 URL 的末尾。最后,您必须提供将重定向用户的redirect_uri参数(将帖子ID作为查询参数包含在内),因此您必须在该URL上有一些东西来处理响应。
关于http://mobile.twitter.com/home?status URL,我学到了一些东西:首先,状态中包含的任何 URL 都不会被缩短(糟糕);其次,如果您的状态包含任何单引号,它们将被编码为 ' (HTML 实体代码),但在您发布推文时不会被解码。但是,如果您使用相同的 URL 通过桌面发布,则不会发生这种情况。您可以通过在 iPhone(我在 iPhone 上使用 Safari)和桌面(我在使用 Safari)上尝试以下 URL 来明白我的意思:
http://mobile.twitter.com/home? status=Wayne's%20World
注意,我对状态执行了 javascript 编码URI,但单引号通常不是大多数 URL/I 编码器可编码的字符。有些会用 %27 替换单引号,但我尝试手动插入它,但它仍然没有在状态文本中解码。
我希望这些信息可以帮助那些来这里寻找简单的 Facebook 和 Twitter 共享选项的人。
A couple of notes regarding Simpleton's answer.
The http://m.facebook.com/sharer.php URL may not be what you want. The site that you provide in the u query parameter needs to have some tags in the page in order for the share
page to be at all interesting. Just try putting another URL in there other than Google to see what I mean. I was never really able to figure out what it is looking for in the page of the site in order to show anything useful in your share page. I did not see any way to provide extra information about the site you are sharing.
The t query parameter is no longer read by facebook as far as I could tell
I found that the Facebook feed dialog was a better sharing alternative (https://developers.facebook.com/docs/reference/dialogs/feed/). See the example at the bottom of that page for the information you can share. Paste that example URL in to your browser to see what it looks like. You can play around with the parameters to see what each parameter controls in the post. For example, if you don't provide the caption parameter, it seems that the base URL of the link parameter is used in it's place. To use the feed dialog approach, you need to register your app in Facebook to get an app_id that you will need to include in the feed dialog URL. You also associate your app with a web site URL, which you also use in the feed dialog URL. If you want Facebook to serve you a mobile-friendly page, append &display=touch to the end of the feed dialog URL. Lastly, you must provide redirect_uri parameter where the user will be redirected (with the post ID included as a query parameter), so you have to have something at that URL to handle the response.
Regarding the http://mobile.twitter.com/home?status URL, I learned a couple of things: first, any URL's in include in the status will not be shortened (bummer); second, if your status includes any single quotes, they will be encoded as ' (HTML entity code) but will not get decoded when your post the tweet. However, this doesn't happen if you are posting via the desktop, using the same URL. You can see what I mean by trying the following URL from both your iPhone (I was using Safari on iPhone) and then from your desktop (I was using Safari):
http://mobile.twitter.com/home?status=Wayne's%20World
Note, I do an javascript encodeURI on the status, but single quotes are not generally encodable characters by most URL/I encoders. There are some that will replace the single quote with a %27, but I tried inserting that manually and it still didn't get decoded in the status text.
I hope this information helps someone comes here looking for simple Facebook and Twitter sharing options.
Twitter - 这就是我通过 url 解决所有设备/浏览器问题的推文的方法:
encodeURIComponent - 是一个内置的 javascript 函数,解释为 此处。
不支持“http://mobile.twitter.com/home?status=” ,当 Twitter 请求登录时,您将遇到编码问题。
Facebook - 对于 Facebook 共享,我使用了 Facebook API 示例
Twitter - This is how I solved the tweet by url for all devices/browsers issue:
encodeURIComponent - is a built in javascript function, explained here.
The 'http://mobile.twitter.com/home?status=' is not supported, and you will get encoding issues when twitter requests a login.
Facebook - For facebook sharing I used Facebook API example
网址没问题,但您需要在服务器上做一些工作才能让 Facebook 真正使其看起来像样。 Facebook 现在使用“Open Graph”,它允许您向 Facebook 理解的网页添加特殊标签。您可以定义页面上的媒体类型,甚至可以使用您在 Facebook 应用程序中创建的定义添加自己的对象。开发者开放图谱对象页面的链接位于此处。
详细信息页面上的开放图示例可能如下所示:
等等。这一切都位于您向 Facebook 提供的实际 url 页面的
中。然后 Facebook 会将其翻译成适当的帖子。此外,您需要在应用程序开发人员页面上设置开放图谱,以便 Facebook 知道寻找 og: 标签。这很复杂,但确实有效。
祝你好运!
The url is ok, but you need to do some work on your server to get Facebook to really make it look decent. Facebook now uses "Open Graph", which allows you to add special tags to your web page that Facebook understands. You can define what types of media are on the page, even add your own objects with definitions you create inside your Facebook app. The link to the developer Open Graph objects page is Here.
A sample of Open Graph on a detail page might look like this:
And so on. This all goes in the
<head>
of the page of the actual url you are supplying to Facebook. Then Facebook will translate this into the appropriate post. In addition, you need to set up the Open Graph on your apps developer page, so that Facebook knows to look for the og: tags. It's complicated, but it does work.Good luck!