我试图让我的列表中的所有成员(大约19,000名成员)并使用C#中的Mailchimp.NET.V3包。
以下代码仅检索前1000个成员
IMailChimpManager MC = new MailChimpManager(@"xxxxxxxxxxxxxxxxxxxxxxxxx-xxx");
var listMembers = await MC.Members.GetAllAsync(ListId);
我也尝试使用MemberRequest
构造函数,但这永远不会返回任何值。
var listMembers = await MC.Members.GetAllAsync(ListId, new MemberRequest { Limit = 20000 } );
有人可以帮忙吗?谢谢!
答案 0 :(得分:0)
你需要使用'计数'参数,不限制。
答案 1 :(得分:0)
使用偏移值。
List<Member> listMembers = new List<Member>();
IMailChimpManager manager = new MailChimpManager(MailChimpApiKey);
bool moreAvailable = true;
int offset = 0;
while (moreAvailable)
{
var listMembers = manager.Members.GetAllAsync(yourListId, new MemberRequest
{
Status = Status.Subscribed,
Limit = 250,
Offset = offset
}).ConfigureAwait(false);
var Allmembers = listMembers.GetAwaiter().GetResult();
foreach(Member member in Allmembers)
{
listMembers.Add(member);
}
if (Allmembers.Count() == 250)
//if the count is < of 250 then it means that there aren't more results
offset += 250;
else
moreAvailable = false;
}
答案 2 :(得分:0)
我在统一3D上使用C#脚本进行了类似的操作,并具有基本身份验证和WWW请求。该脚本使用API 3.0返回Mailchimp上列表的成员。也许这段代码会有所帮助。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mailchimpRESTful : MonoBehaviour
{
/*
* USE using CURL:
*
curl --request GET \
--url 'https://<dataCenter>.api.mailchimp.com/3.0/lists/<your-list-name>/members/' \
--user 'anystring:<mailchimp-api-key>'
EXAMPLE using CURL:
curl --request GET \
--url 'https://us12.api.mailchimp.com/3.0/lists/era987af43/members/' \
--user 'anystring:e419ac3fefefgkjne0559901222a3dbf-us12'
*/
// Mailchimp API RESTful C# script GET Member list
private const string DC = "<your-data-center>"; // us1,us2..us18
private const string LIST = "<your-list-name>"; // Something similar to: era987af43
private const string URL = "<your-url>"; // "https://<dataCenter>.api.mailchimp.com/3.0/lists/<your-list-name>/members/";
private const string USER = "anystring"; // You can use any user
private const string API_KEY = "your-api-key"; // Mailchimp API-key: e419ac3fefefgkjne0559901222a3dbf-us12
public void Start()
{
Request ();
}
public void Request()
{
Dictionary<string, string> headers = new Dictionary<string,string>();
headers ["Authorization"] = "Basic " + System.Convert.ToBase64String (System.Text.Encoding.ASCII.GetBytes (USER + ":" + API_KEY));
WWW request = new WWW(URL, null, headers);
StartCoroutine (OnResponse (request));
}
private IEnumerator OnResponse(WWW req)
{
yield return req;
Debug.Log ("Query Result:"+req.text);
}
}
答案 3 :(得分:0)
private async Task<List<Member>> GetMemberListAsync(string listId)
{
var offset = 0;
var moreAvailable = true;
var listMembers = new List<Member>();
while (moreAvailable)
{
var result = await manager.Members.GetAllAsync(listId, new MemberRequest
{
Status = Status.Subscribed,
Limit = 250,
Offset = offset
});
var resultList = result.ToList();
foreach (var member in resultList)
{
listMembers.Add(member);
}
if (resultList.Count() == 250)
offset += 250;
else
moreAvailable = false;
}
return listMembers;
}
答案 4 :(得分:-1)
var listMembers = manager.Members.GetAllAsync(ListId).ConfigureAwait(false);
var Allmembers = listMembers.GetAwaiter().GetResult();