如何使用c#从常量联系人获取UserContactLists

本文关键字:联系人 获取 UserContactLists 常量 何使用 | 更新日期: 2023-09-27 17:52:57

我将使用Constant contact进行电子邮件营销。我不知道如何得到userContactList这都在我的恒定联系人帐户。如果有人有任何想法,请帮助我。提前感谢

如何使用c#从常量联系人获取UserContactLists

这是我不久前写的一些代码,它根据现有用户列表的名称返回用户列表ID。它全是c#,使用RESTSharp库,你可以使用Nuget将其安装到你的VS项目中。

            public static string GetContactListIDByListName(string listname)
            {
                feedData = string.Empty;
                id = string.Empty;
                name = string.Empty;
                status = string.Empty;
                modified_date = string.Empty;
                created_date = string.Empty;
                contact_count = 0;

                Stream stream = null;
                StreamReader streamReader = null;
                var client = new RestClient(ccURL);
                var request = new RestRequest("/v2/lists?modified_since=[DATE]&api_key=[API-KEY]", Method.GET);
                request.AddHeader("Authorization", "Bearer [ACCESS-TOKEN]");
                request.AddHeader("X-Originating-Ip", "[SERVER-IP]");
                request.AddHeader("Accept", "application/json");
                IRestResponse response = client.Execute(request);
                feedData = response.Content;
                // DESERIALIZE Mashery JSON Response
                byte[] byteArray = Encoding.ASCII.GetBytes(feedData);
                MemoryStream myStream = new MemoryStream(byteArray);
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Mashery.GetAllListsDef[]));
                object result = serializer.ReadObject(myStream);
                Mashery.GetAllListsDef[] jsonObj = result as Mashery.GetAllListsDef[];

                foreach (Mashery.GetAllListsDef myResult in jsonObj)
                {
                    if (myResult.name.ToUpper().Equals(listname.ToUpper()))
                    {
                        return myResult.id.ToString();
                    }
                }
                return "";
            }
            // JSON Definition For [GET All Lists] End Point Method
            [Serializable, XmlRoot("GetAllListsDef"), DataContract(Name = "GetAllListsDef")]
            public class GetAllListsDef
            {
                [XmlElement("id"), DataMember(Name = "id")]
                public string id { get; set; }
                [XmlElement("name"), DataMember(Name = "name")]
                public string name { get; set; }
                [XmlElement("status"), DataMember(Name = "status")]
                public string status { get; set; }
                [XmlElement("created_date"), DataMember(Name = "created_date")]
                public string created_date { get; set; }
                [XmlElement("modified_date"), DataMember(Name = "modified_date")]
                public string modified_date { get; set; }
                [XmlElement("contact_count"), DataMember(Name = "contact_count")]
                public string contact_count { get; set; }
            }