0

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.

Codehelp
  • 4,157
  • 9
  • 59
  • 96

1 Answers1

1

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.

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
  • Ok will try that, can you please tell me why I am getting No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:port' is therefore not allowed access. – Codehelp Jun 30 '14 at 10:47
  • I see this in FF devtools XMLHttpRequest cannot load https://api.twitter.com/oauth/authorize?oauth_token=NqPnwFXEN65gNCqyeRPMhMuip6h. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:32950' is therefore not allowed access. – Codehelp Jun 30 '14 at 11:00
  • Make sure you aren't using InProc session - always a gottcha because session recycles. You might try to get the sample application working - you can find that in the downloadable source code. That will help iron out any basic communications issues. I have some documentation that explains oauth in more detail: http://linqtotwitter.codeplex.com/wikipage?title=Learning%20to%20use%20OAuth&referringTitle=Securing%20Your%20Applications I also have a FAQ that helps work through OAuth 401 issues: http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation – Joe Mayo Jul 01 '14 at 03:34
  • Thanks Joe. Appreciate your help. – Codehelp Jul 01 '14 at 06:42