Mailchimp 错误 400 请求,无法将用户发送到列表
Mailchimp error 400 request, can't send users to list
我正在使用 Mailchimp,我想将一个电子邮件地址发送到我的列表中,到目前为止,我已经使用 Volley 完成了此操作:
public void suscribeMailChamp(){
String listid = "listID";
String url = "https://us16.api.mailchimp.com/3.0/lists/" + listid + "/members/";
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest sr = new StringRequest(Request.Method.POST,url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//
Toast.makeText(MainActivity.this , "success" , Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this , error.toString() , Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("email_address","testmailchimp@gmail.com");
params.put("status","unsubscribed");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("Content-Type","application/x-www-form-urlencoded");
params.put("Authorization" , "apikey <here my api key>");
return params;
}
};
queue.add(sr);
}
但我收到错误 400:
Unexpected response code 400 for
https://us16.api.mailchimp.com/3.0/lists/b9a5943047/members/
这里有一个 link 用于故障排除,但我无法得到错误:
http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
你检查过link中的错误了吗?它说
{
"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
"title":"API Key Missing",
"status":401,
"detail":"Your request did not include an API key.",
"instance":"924c81cc-90e9-498d-b0fd-c7b54cba207f"
}
这意味着您没有(或正确地)在请求中为邮件黑猩猩发送 API 密钥。只需在 Volley
请求
的参数中添加 mailChimp API 键
所以您发送 API 密钥的方式是
params.put("Authorization", "Basic "+Base64.encodeToString(("apikey:"+apiKey).getBytes("UTF-8"),Base64.DEFAULT))
我也卡在这上面了。 Mailchimp 文档非常差。
我找到了解决方案 from github
只需在您的 header
中发送 'Authorization': 'apikey myapikey'
我正在使用 Mailchimp,我想将一个电子邮件地址发送到我的列表中,到目前为止,我已经使用 Volley 完成了此操作:
public void suscribeMailChamp(){
String listid = "listID";
String url = "https://us16.api.mailchimp.com/3.0/lists/" + listid + "/members/";
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest sr = new StringRequest(Request.Method.POST,url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//
Toast.makeText(MainActivity.this , "success" , Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this , error.toString() , Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("email_address","testmailchimp@gmail.com");
params.put("status","unsubscribed");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("Content-Type","application/x-www-form-urlencoded");
params.put("Authorization" , "apikey <here my api key>");
return params;
}
};
queue.add(sr);
}
但我收到错误 400:
Unexpected response code 400 for https://us16.api.mailchimp.com/3.0/lists/b9a5943047/members/
这里有一个 link 用于故障排除,但我无法得到错误:
http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
你检查过link中的错误了吗?它说
{
"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
"title":"API Key Missing",
"status":401,
"detail":"Your request did not include an API key.",
"instance":"924c81cc-90e9-498d-b0fd-c7b54cba207f"
}
这意味着您没有(或正确地)在请求中为邮件黑猩猩发送 API 密钥。只需在 Volley
请求
所以您发送 API 密钥的方式是
params.put("Authorization", "Basic "+Base64.encodeToString(("apikey:"+apiKey).getBytes("UTF-8"),Base64.DEFAULT))
我也卡在这上面了。 Mailchimp 文档非常差。 我找到了解决方案 from github
只需在您的 header
中发送 'Authorization': 'apikey myapikey'