首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.NET C# aWeber API

.NET C# aWeber API
EN

Stack Overflow用户
提问于 2014-02-11 16:50:03
回答 1查看 1K关注 0票数 0

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

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

总之,以下是我的问题:

  1. 对于如何使用无人值守的服务来完成这项任务,有什么建议吗?
  2. 有人做过这个吗?

任何帮助都是非常感谢的。

谢谢

艾玛

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-28 11:46:33

代码语言:javascript
复制
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 = api.getAccount();
  • 要获取EmailID、IP地址等list.Refer上的订户到此链接https://labs.aweber.com/docs/permissions int listid = int.Parse(ConfigurationManager.AppSettings"ListId");foreach (account.lists().entries中的列表列表){ if (list.id == listid) { foreach (list.subscribers().entries中的订户){我们执行订阅者的电子邮件是否存在于列表中的检查&因此从列表中删除它。if (subscriber.email == eid & subscriber.status !=“未确认”){尝试{ if (subscriber.delete()) {//Response.Wrett(“订户成功删除”);{}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21707945

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档