【发布时间】:2015-08-02 08:05:08
【问题描述】:
我正在尝试通过新的 3.0 REST API 访问我们的 MailChimp 帐户。我做了以下事情:
using(var http = new HttpClient())
{
var creds = Convert.ToBase64String(Encoding.ASCII.GetBytes("username:mailchimpapikey-us1"));
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", creds);
string content = await http.GetStringAsync(@"https://us1.api.mailchimp.com/3.0/lists");
Console.WriteLine(content);
}
但是,当我运行此代码时,我收到一个 401 错误,其中包含以下 json 详细信息:
{"type":"http://kb.mailchimp.com/api/error-docs/401-api-key-invalid","title":"API Key Invalid","status":401,"detail":"Your API key may be invalid, or you've attempted to access the wrong datacenter.","instance":"a9fe4028-519e-41d6-9f77-d2caee4d4683"}
我在 URI 中使用的数据中心(本例中为 us1)与我的 API 密钥上的 dc 匹配。如果我使用 MailChimp SDK,我的 API 密钥有效,所以我知道我的密钥不是无效的。此外,使用 Fiddler,我可以看到 MailChimp SDK 调用的 dc 与我在 URI 中所做的相同。
关于我为什么无法进行身份验证的任何想法?
编辑 如问题中所述,我专门询问有关访问新的 3.0 REST API 的问题。我正在尝试直接执行此操作,而不是使用第三方包装器。
新 API 由 http 调用组成,因此应该非常简单。我只是在身份验证方面遇到了问题。
【问题讨论】:
标签: c# http mailchimp mailchimp-api-v3.0