我正在开发一个Android应用程序,我有订阅对话框来收集用户的电子邮件。我想将这些用户电子邮件添加到MailChimp列表中。这是我到目前为止提出的代码,但是我得到了Authorization failed
错误。
public void suscribeMailChamp(String 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","oshan@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");
return params;
}
};
queue.add(sr);
}
答案 0 :(得分:0)
在此代码行中插入您的API密钥
params.put("Authorization" , "apikey");
答案 1 :(得分:0)
我知道这是一个旧帖子,但对于其他遇到麻烦的人,我在复制api键之前添加了“apikey”这个词来解决这个问题,如下所示:
params.put("Authorization" , "apikey <YOUR API KEY HERE>");