Sharing to Facebook, Twitter and email in Windows Phone 7
Recently I needed to implement sharing capabilities for Facebook, Twitter and email in one Windows Phone app I’m currently working on. Just for fun I also added sharing through SMS messaging.
We are all aware of default sharing page, which is included in Pictures hub and allows you to share to various networks and applications, so I wanted to recreate this look also in my app (you can download it on my SkyDrive):
Sharing a link through email is easy, just 4 lines of code:
EmailComposeTask email = new EmailComposeTask(); email.Subject = title; email.Body = "Read all about it here: " + link; email.Show();
For sending SMS messages is totally same, just the object is SmsComposeTask and there is no title. There are several more launchers and choosers in Microsoft.Phone.Tasks namespace, you can read more about that here.
OK, so for Facebook and Twitter there are some complications, since you need to implement oAuth protocol. Basically it means, that my app doesn’t know anything about user’s credentials, but for doing that, we need a little hacking with browser control.
For Facebook there is already Facebook Toolkit and from latest version there is also support for Windows Phone apps. So there is no surprises, you just need to implement a lot of code, just because there is a lot of ping-pong communication going on. But hey, that’s why I did this sample, so you won’t have to!
Twitter implementation is using some bits of code from Twitt – Windows Phone 7 Twitter App, which is basic Twitter app for demoing purposes, but it’s very solid and well build example.
UPDATE: I forgot to mention, that you need to create application in Facebook (go for more info here – you will need Facebook account for that). By doing that, you will get Application ID. Insert this string in Helpers/FacebookSettings.cs and you’re ready to go.
For Twitter is almost the same – go here (again, you will need Twitter account for that) and create browser application (it’s because I’m using same app in my web application), where you’ll get consumer key and consumer key secret (and some more keys, but they are not relevant for this case). Enter those into Helpers/TwitterSettings.cs.
So that’s that, tell me what you think and don’t forget to download sample code here.
| Tweet |
author: Aleš Rosina | Comments: 13 |
May
2011
I hope this is soon possible in XNA games too. When XNA can finally use Silverlight controls that is, with the Mango update.
Hi,
Very gud post. I have seen the sample but when i tried to run the application, i was unable to connect to facebook and twitter. do we have to pass any parameters for that. could you please suggest me on this.
This URL when i tried to run in the browser, i was getting error as wl.this is the URL used to navigate when trying to share from mainpage.xaml to sharepage to share content to facebook
Hi!
Yeah, forgot to mention that :) I've just updated blog post - you will need to create application in facebook developer portal. The same goes with Twitter.
Sorry about that, was writting in a hurry and forgot to mention about creating facebook app.
hi ,
I took twitter API key. But wwhat should be i specify in the application website column. As for Windows phone 7 it is an client application.
Yeah, for this case it should be web application. It is client, but I did it this way :)
Hey,
I got it. Thanks alot. I have been wondering how to do sharing files with linkedin. Is this the same way?
You shold check developer.linkedin.com for LinkedIn implementation. I haven't had time for linkedin implementation, but i guess I shouldn be that hard, since they use the same approach.
HI,
I'm trying to post title along with the link in the facebook, but I'm unable to post the title. I'm able to post only link. Y this strange behavior. could you please suggest me on this.
Thanks a lot for the post!!!! It is very good and easy implemented. I have a problem with the twitter connection, it does not connect it even does not show the login page and a message box appears and says there is a problem.
Thanks a lot.
hi, could you please post application for sharing to linkedin, i tried alot but, was not successfulll.
I have searched many blogs but there isnt any one use ful.
thanks in advance
hi,
I tried to compile the app but getting an error message
"Error 1 The type or namespace name 'PerformanceProgressBar' does not exist in the namespace 'Microsoft.Phone.Controls' (are you missing an assembly reference?) C:\WP7\test\SharingApp\SharingApp\SharingApp\obj\Debug\Sharing.g.i.cs 49 43 SharingApp
"
You need to add Silverlight toolkit to project. You can add that through nuget in Visual stuio or downlod from codeplex.
Hi, this is great..
thanks for your share, but i want to ask how i can share the link with thumbnail?

