Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook and twitter share for mobile web

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.

like image 251
resting Avatar asked Aug 25 '11 08:08

resting


People also ask

How do I get my URL for Twitter?

Open a web browser and input Twitter.com into the address bar. Find the profile icon in the left column and click it. Your browser's address bar at the top of the screen will display your Twitter URL as twitter.com/username.

How do I share a website item on Facebook?

Log in to Facebook and select "Create a Page" from the bottom of any Facebook page, then select "Product or Service." Fill in the name of your business or product, tick the box to agree to Facebook's "Terms of Service" and click "Get Started." Add the details of the fan page, including a "Profile Picture" and basic ...


2 Answers

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:

http://m.facebook.com/sharer.php?u=<urlencoded url>t=<urlencoded title>

For example:

http://m.facebook.com/sharer.php?u=http://www.google.com

Updating status on Twitter:

http://mobile.twitter.com/home?status=<urlencoded status>
like image 167
Simpleton Avatar answered Oct 22 '22 00:10

Simpleton


A couple of notes regarding Simpleton's answer.

  1. 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.

  2. The t query parameter is no longer read by facebook as far as I could tell

  3. 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.

  4. 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.

like image 11
mbeaty Avatar answered Oct 22 '22 00:10

mbeaty