0

我已经按照文档步骤进行操作,直到第 5 步,一切都很顺利。

成功授权后,我尝试访问帐户数据,如步骤 5

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

我在 api.getAccount() 上有 401 异常;

请告诉我我错过了什么?我究竟做错了什么?

谢谢

4

1 回答 1

0

我找到了解决方案。为了其他人有同样的问题,这里是功能齐全的代码示例

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();       
        }
    }
于 2014-08-20T09:36:54.927 回答