【问题标题】:RestSharp / MailChimp 'API key missing' errorRestSharp / MailChimp'API 密钥丢失'错误
【发布时间】:2016-05-29 10:54:27
【问题描述】:

当我使用 RestSharp 在 Mailchimp 上发布活动时,它告诉我我的 API 密钥丢失,但是当我单击“获取活动”时,它成功地向我显示了所有活动数据。

谁能告诉我哪里出错了?这是我的代码:

public MailChimpPostModel PostCampaign(MailChimpPostModel post)
{
    var auth = _userBusinessObject.GetUserWebsiteAuthorizationByWebsite(_userId, 
                                                                   _websiteId,
                                                                   _linkvanaNetworkSiteId);
    ApiBaseUrl = <url> ;
    if (auth == null)
        throw new RestRequestResponseException { Error = RestErrorsEnum.NotAuthenticated };

    var request = new RestRequest(3.0/campaigns, Method.POST);
    request.AddParameter("access_token", <Token>);
    request.AddParameter("apikey", <Token> + "-" + <dc>);
    request.AddHeader("content-type", "application/json");
    request.AddBody(post);
    var response = Execute<MailChimpPostModel>(request);
    return response;
}

【问题讨论】:

  • 我已经稍微改进了这篇文章的语法和格式 - 希望它会让其他人更容易回答你。
  • 可能有错字?更改:request.AddParameter("apikey", + "-" + ); to:request.AddParameter("apikey", + "-" + );
  • AddParameter 是否添加到查询字符串中?如果是这样,那就是问题所在。这不是 POST 支持的身份验证方法。它仅对 GET 启用以使调试更容易一些。您需要使用 HTTP 基本身份验证。

标签: asp.net-mvc mailchimp restsharp mailchimp-api-v3.0


【解决方案1】:
// replace usX to match the last 3 of your API
var client = new RestClient("https://usX.api.mailchimp.com/3.0/");
client.Authenticator = new HttpBasicAuthenticator("user", APIKey);

【讨论】:

    猜你喜欢
    • 2019-12-14
    • 2021-10-20
    • 2016-01-03
    • 2017-06-18
    • 1970-01-01
    • 2021-08-31
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多