首页 文章

.NET C#aWeber API

提问于
浏览
0

使用.NET c#我需要使用API以编程方式管理/添加订阅者到aWeber中的列表 . 我负责的过程将是一个Windows服务,每天运行x次,并更新aWeber的订户及其所在的列表 .

所以我使用带有.NET的aWeber API的所有研究都告诉我,必须完成aWeber的登录页面才能在回调URL中接收oauth_verifier .

总结这里是我的问题:

  • 有关如何使用无人值守服务完成此任务的任何建议?

  • 有没有人这样做?

任何帮助是极大的赞赏 .

谢谢

艾玛

1 回答

  • 1
    1) How to use Aweber .NET SDK to connect with Aweber account [Regular Account - (i.e.) Not the developer's one].
    
       Download .NET SDK for Aweber from https://aweber.codeplex.com/
    
    Ans :- 1) Create a developer account - Visit https://labs.aweber.com/
    
           2) As you have successfully created the account you would see ConsumerKey,                            ConsumerSecret, & an AppId in your Application.
    
           3) Then for the fist time add the following code.
    
    string ConsumerKey = ConfigurationManager.AppSettings["AWeberConsumerKey"];
    string ConsumerSecret= ConfigurationManager.AppSettings["AWeberConsumerSecret"];
    
    Aweber.API api = new Aweber.API(ConsumerKey, ConsumerSecret);
    
    api.CallbackUrl = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/Authorize/Index";
    
    api.get_request_token();
    
    Response.Cookies["oauth_token"].Value = api.OAuthToken;
    Response.Cookies["oauth_token_secret"].Value = api.OAuthTokenSecret;
    
    api.authorize();
    
    **Now create An Authorize controller in case of MVC or Authorize.aspx**
    
    string ConsumerKey = ConfigurationManager.AppSettings["AWeberConsumerKey"];
    string ConsumerSecret= ConfigurationManager.AppSettings["AWeberConsumerSecret"];
    
    API api = new API(ConsumerKey, ConsumerSecret);
    
    api.OAuthVerifier = Request["oauth_verifier"];
    
    Response.Cookies["access_token"].Value = api.get_access_token();
    
    Account account = api.getAccount();
    
    **Now you can apply your code to create, delete... subscribers to/from the list**
    
       When you run this code first the authorize page will appear where you need to add your Aweber regular account credentials.
    
      Once it's verified then you'll get access to the aweber's(Customer) account.
    
      **But you would not like the authorize page appear always whenever you run your application so you can omit it by doing the following steps.**
    
    
    
     1. Use the PHP script provided in  http://stackoverflow.com/questions/15378034/how-to-create-an-app-in-aweber
    
    
     2. Run the above PHP script & you'll get the pair of accesskey & accesssecret.Copy them to your C# code (these are the permanent keys).   
    
    
     3. Initialize the API with this code:
    
        string ConsumerKey = ConfigurationManager.AppSettings["AWeberConsumerKey"];
        string ConsumerSecret = ConfigurationManager.AppSettings["AWeberConsumerSecret"];    
    
        string accessKey = ConfigurationManager.AppSettings["accessKey"];
        string accessSecret = ConfigurationManager.AppSettings["accessSecret"];
    
        Aweber.API api = new Aweber.API(ConsumerKey, ConsumerSecret);
    
        api.OAuthToken = accessKey;
        api.OAuthTokenSecret = accessSecret;
    
        Account account = api.getAccount();
    
        **Now we'll code to create subscriber to a particular list** 
    
          int listid = int.Parse(ConfigurationManager.AppSettings["ListId"]);
    
          foreach (List list in account.lists().entries)
          {
    
               if (list.id == listid) Your List's ID **(Mylist - xxxxxxx)**
               {
    
                    foreach (Subscriber subscriber in list.subscribers().entries)
                    {
    
                       if (subscriber.email.Equals(objRegModel.EmailID))
                       {
                             flag = false;
                             break;
    
                             **Checks whether the similar subscriber exists on the list**
                        }
                        else
                        {
                             flag = true;
    
                         }
    
                     }
    
    
                if (flag == true)
                {
                 BaseCollection<Subscriber> target = list.subscribers();
    
                 SortedList<string, object> parameters = new SortedList<string, object>();
    
                 parameters.Add("email", objRegModel.EmailID);
    
                 parameters.Add("name", objRegModel.FirstName + " " + objRegModel.LastName);
    
                 Subscriber subscriber = target.create(parameters);
    
                 **This will add the subscriber to the specified list only if does not exist on that list.**
                }
    
            }
    
       }
    
       **To Delete a particluar subscriber from the list**
    
    int listid = int.Parse(ConfigurationManager.AppSettings["ListId"]);
    
        foreach (List list in account.lists().entries)
        {
    
            if (list.id == listid)
            {
    
                foreach (Subscriber subscriber in list.subscribers().entries)
                {
                    We Perform the check whether the email of the subscriber exists on the list or not & accordingly delete it from the list.
    
                    if (subscriber.email == eid && subscriber.status != "unconfirmed")
                    {
                        try
                        {
                            if (subscriber.delete())
                            {
                                //Response.Write("Subscriber Successfully Deleted");
                            }
                        }
                        catch (Exception ex)
                        {
    
                        }
                    }
    
                }
            }
        }
    }
    

相关问题