-1

I am creating a web app for a project. I want to allow my users to post there blogs onto twitter using the twitter API. they will generate a blog inside my website and if they would like to share their blog via twitter. No so much testing if the Twitter API works, more as if it works inside of my website, as in if my syntax is appropriate, and if how i am incorporating it is correct. Its for a class project.

1 Answers1

0

Assuming you are using C# / ASP.NET, you would be writing a class to make your API calls which can be tested independently. I would suggest downloading the open source Twitterizer DLL and plugging that into your web project, mostly for the OAuth implementation.

So, if you were posting a Tweet, you could write a static method as follows:

public static bool CreateTweet(Twitterizer.OAuthTokens tokens, string tweetText)
{
    var response = Twitterizer.TwitterStatus.Update(tokens, text);
    return response.Result == Twitterizer.RequestResult.Success;
}

And your test code would look like this:

    void Test()
    {
        var tokens = new Tw.OAuthTokens
            {
                _accessToken,
                _accessTokenSecret,
                _consumerKey,
                _consumerSecret,
            };

        var testTweet = "test tweet text";
        CreateTweet(tokens, testTweet);
    }

You would need to obtain the tokens either via Twitter's login process or have them stored if you don't expect users to log in.

And then basically the test code above would be moved into the appropriate piece of code-behind in your ASP.NET application and it should just work!

James Harcourt
  • 6,017
  • 4
  • 22
  • 42