Aweber API .NET SDK 401未经授权的例外

时间:2014-08-19 16:28:03

标签: c# .net api aweber

我已按照文档步骤操作,一切顺利,直到第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例外

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

由于

1 个答案:

答案 0 :(得分: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();       
        }
    }