Note that there are some explanatory texts on larger screens.

plurals
  1. PODotNetOpenAuth Twitter API Version 1.1 calls in MVC4
    primarykey
    data
    text
    <p>I am writing an MVC4 Web Application that has to query the Twitter Version 1.1 API. Built into MVC4, I can use the "Sign in with Twitter" function when I just activate <strong>OAuthWebSecurity.RegisterTwitterClient</strong> in <strong>AuthConfig.cs</strong>. This then authenticates the Twitter login, but what I want to do is authorize the user so that I can make API v1.1 calls on behalf of the user.</p> <p>I have found <a href="https://stackoverflow.com/questions/13034084/mvc4s-dotnetopenauth-twitterclient-sample-does-not-respect-prior-login">this post</a> on Stack Overflow which uses custom classes to address something different (the force_login parameter issue), but I have used these classes and changed the <strong>UserAuthorizationEndpoint</strong> to point to <strong>oauth/authorize</strong>. I changed this line of code:</p> <pre><code>UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/authenticate", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), </code></pre> <p>to this:</p> <pre><code>UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/authorize", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), </code></pre> <p>It works for the authorization, which means now my application authorizes the Twitter user. However, when I make calls to the API v1.1, I get the '(401) Unauthorized' error. This is the code I use for the call:</p> <pre><code>var var1 = WebWorker.PrepareAuthorizedRequest(new MessageReceivingEndpoint("https://api.twitter.com/1.1/followers/ids.json?cursor=-1&amp;screen_name=sitestreams", HttpDeliveryMethods.GetRequest), accessToken); var var2 = var1.GetResponse(); </code></pre> <p>I think I also need the <strong>oauth_token_secret</strong> for the call to be authorized. Can DotNetOpenAuth give me the <strong>oauth_token_secret</strong>? Can I then use <strong>WebWorker.PrepareAuthorizedRequest</strong> to also send the <strong>oauth_token_secret</strong>?</p> <p>I have also found <a href="https://stackoverflow.com/questions/12198734/getting-twitter-access-secret-using-dotnetopenauth-in-mvc4">this post</a> on Stack Overflow which says I can't use DotNetOpenAuth for this. However, the DotNetOpenAuth code has been updated since, and I want to know if it now caters for what I want to do, which is in essence a very simple thing: allow a user to login on my web application using Twitter, and then allow my web application to see the user's followers.</p> <p>So it boils down to this: Can I use <strong>DotNetOpenAuth</strong> in MVC4 to authorize the user and then call the Twitter API v1.1 on the user's behalf, for instance to <em>GET followers/ids</em>. If possible, how do I do it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload