访问MailChimp API 3.0(GET) [英] Access MailChimp API 3.0 (GET)

查看:138
本文介绍了访问MailChimp API 3.0(GET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过jQuery向Mailchimp API发出GET请求.似乎我收到Your request did not include an API key.错误时,没有正确设置我的自定义标头.

I'm trying to make a GET request through jQuery to the Mailchimp API. It seems though my custom header is not correctly set as I get a Your request did not include an API key. error.

如果我在Ubuntu机器上使用curl发出请求,效果很好:

It works fine if I make the request using curl on my Ubuntu machine:

curl --header "Authorization: apikey 709XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us11" https://us11.api.mailchimp.com/3.0/campaigns

这是我的代码:

$.ajax({
    type: 'GET',
    url: 'https://us11.api.mailchimp.com/3.0/campaigns',
    crossDomain: true,
    dataType: 'jsonp',
    contentType: "application/json; charset=utf-8",
    headers: {
        'Authorization': 'apikey 709XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us11'
    }
}).done(function (response) {
    console.log(response); // verbose
});

我什至尝试在上面添加以下内容:

I even tried adding this above:

$.ajaxSetup({
    headers: { 'Authorization': 'apikey 709XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us11' }
});

推荐答案

您需要通过Basic Auth添加密钥,据我所知,您不能从前端查询它,它必须处于打开状态后端.

You need to add the key via Basic Auth like and as far I am aware off, You can't query it from front-end, it must be on the back-end.

在NodeJS中查找示例:

Find an example in NodeJS:

headers: {
    'Authorization': 'Basic ' + new Buffer(`anything:${MailChimpKey}`).toString('base64');
}

这篇关于访问MailChimp API 3.0(GET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆