Codehelp
Codehelp

Reputation: 4747

Updating Twitter status using LinqToTwitter

here's what set out to do:

  1. Make an MVC app on which the user clicks a button and is taken to the Twitter login page
  2. After giving the credentials the user is redirected to a second page
  3. On the secong page there is a text box and a 'Tweet' button
  4. Entering a message and clicking on 'Tweet' will update the status

I got till the 2nd point by following the samples from LinqToTwitter codeplex page.

The code from OAuth controller works fine and it does redirect back to MVC app's second page.

But I am missing something which is not posting the status.

This is the code in the button click from which I pass the user entered status:

public ActionResult Status(string status)
    {
        var auth = new MvcAuthorizer
        {
            CredentialStore = new SessionStateCredentialStore()
        };

        auth.CompleteAuthorizeAsync(Request.Url);

        var twitterContext = new TwitterContext(auth);

        TweetAsync(twitterContext, status);

        return View(); //return some view to the user
    }

    void TweetAsync(TwitterContext twitterCtx, string statusToUpdate)
    {
        var tweet =  twitterCtx.TweetAsync(statusToUpdate);

        if (tweet != null)
        {
          // Inform the user about success
        }
     } 

Both the above methods are also in OAuth controller.

Can someone please help me with this?

Thanks in advance.

Upvotes: 0

Views: 436

Answers (1)

Joe Mayo
Joe Mayo

Reputation: 7513

Change your method to use async and return a Task:

public async Task Status(string status) { //...

    var tweet = await twitterContext.TweetAsync(twitterContext, status);

    // ...
}

and then await TweetAsync, assigning the response to a Status entity named tweet. If you want a separate method for calling TweetAsync, make that async also. With async, you must make every method in the call chain async.

Upvotes: 1

Related Questions