Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post from twitter using WP7 C#?

I've been looking for a solution to post to twitter from a wp7 app but have found very limited resources on the matter. Everything seems to be in either a different programming language (ex. PHP) or platform (ASP.NET), or is lacking documentation.

These questions did NOT work for WP7:

Post in Twitter using C# application

Twitter post API C#

Post Tweets to Twitter from FaceBook using ASP.Net C#

Are there any resources, code samples or posts that talk about how to get started with the Twitter API for WP7?

Also are there any particular libraries maybe that are well documented that support WP7?

Thanks.

like image 293
Edward Avatar asked Mar 03 '11 00:03

Edward


3 Answers

One popular Twitter library for .Net is TweetSharp. They have a Windows Phone 7 compatible library they have a section which shows sample code for Windows Phone 7. The sample shows how to use the TweetSharp library to retrieve your mentions and post a sample tweet.

If TweetSharp isn't right for you check out the Twitter Libraries page .NET section on the Twitter Developers site for another library with Windows Phone compatablity.

like image 56
Adrian Clark Avatar answered Oct 17 '22 01:10

Adrian Clark


There are a couple of complete twitter apps on codeplex

  • http://twitt.codeplex.com/ - I used this in one of my apps (iron7) but then decided not to enable it in release - so I know this code works!
  • http://mahappstwitter.codeplex.com/

I think both of these also have some associated blogging/documentation which might help - e.g. http://samjarawan.blogspot.com/2010/10/building-real-windows-phone-twitter-app_07.html

like image 28
Stuart Avatar answered Oct 17 '22 02:10

Stuart


The fastest and easiest way is to use Twitter's Tweet Button API. This will make the user leave the page but allows them to modify the tweet how they like. You might be able to make this a little cleaner by embedding a WebBrowser item in your form and making it visible on tweeting.

Here is the code I use:

public class ShareTwitter
{
    // DOCS: http://dev.twitter.com/pages/tweet_button

    private const string URL = "http://twitter.com/share?url={0}&via={1}&text={2}";

    public static void Open(string link, string via, string text)
    {
        WebBrowserTask t = new WebBrowserTask();
        t.URL = String.Format(URL, HttpUtility.UrlEncode(link), HttpUtility.UrlEncode(via), HttpUtility.UrlEncode(text));
        t.Show();
    }
}

I have similar classes for Facebook, ReadItLater and the Windows Phone email - let me know if you're interested in that also.

like image 1
AussieNick Avatar answered Oct 17 '22 03:10

AussieNick