401 Unauthorized when try to access api methods

Aug 19, 2014 at 3:48 PM
Edited Aug 19, 2014 at 5:26 PM
I've followed the documentation steps and everything went smooth until step 5.

After successful authorization I've tried to access account data, like in step 5

var api = new API(ConsumerKey, ConsumerSecret);
api.OAuthToken = "My OAuthToken"; // That I've received on step 4
Account account = api.getAccount();

and I've got 401 exception on api.getAccount();


Please tell me what am I missing? What am I doing wrong?

Thanks
Aug 20, 2014 at 10:34 AM
Edited Aug 20, 2014 at 10:45 AM
I've fixed my problem myself. In case someone has the same issue here is fully functional code:
public class AWeber
    {
        public void Authorize()
        {
            var Session = HttpContext.Current.Session;
            var api = new API(AppSettings.AWebberConsumerKey, AppSettings.AWebberConsumerSecret);
            api.CallbackUrl = "http://localhost:61006/test.aspx"; 
            api.get_request_token();
            Session["OAuthToken"] = api.OAuthToken;
            Session["OAuthTokenSecret"] = api.OAuthTokenSecret;

            api.authorize();
        }

        public void InitAccessToken(string OAuthVerifier)
        {
            var Session = HttpContext.Current.Session;
            var api = new API(AppSettings.AWebberConsumerKey, AppSettings.AWebberConsumerSecret);
            api.OAuthToken = (string)Session["OAuthToken"];
            api.OAuthTokenSecret = (string)Session["OAuthTokenSecret"];
            api.OAuthVerifier = OAuthVerifier;

           // These two are final token that are needed
            Session["OAuthToken"] = api.get_access_token();
            Session["OAuthTokenSecret"] = api.adapter.OAuthTokenSecret;            
        }

        public void GetData()
        {
            var Session = HttpContext.Current.Session;
            var api = new API(AppSettings.AWebberConsumerKey, AppSettings.AWebberConsumerSecret);

            api.adapter.OAuthToken = (string)Session["OAuthToken"];
            api.adapter.OAuthTokenSecret = (string)Session["OAuthTokenSecret"];
            Account account = api.getAccount();       
        }
    }