0

使用 .NET c# 我需要使用 API 以编程方式管理/添加订阅者到我在 aWeber 中的列表。我的任务是一个 Windows 服务,它每天运行 x # 次,并更新 aWeber 上的订阅者和他们所在的列表。

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

所以总而言之,这是我的问题:

  1. 有关如何使用无人值守服务完成此任务的任何建议?
  2. 有人这样做吗?

任何帮助是极大的赞赏。

谢谢

艾玛

4

1 回答 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**       
  • 应用相同的逻辑直到 Account account = api.getAccount();

  • 要获取列表中订阅者的电子邮件 ID、IP 地址等。请参阅此链接https://labs.aweber.com/docs/permissions

       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)
                        {
    
                        }
                    }
    
                }
            }
        }
    }
    
于 2015-01-28T11:46:33.073 回答