Mailchimp API v3授权

问题描述 投票:0回答:3

我的主要目标是将用户添加到列表中。我目前正在使用curl这个术语,以了解使用MailChimp API的概念。

我已完成将用户添加到列表的请求:

curl -i -H "Content-Type: application/json" -d '{"apikey" :  "60dd1f3aaa977bf1zzza159yyye93exx-us11","email_address": "[email protected]","status":"subscribed","merge_fields":{"FNAME":"Urist","LNAME":"McVankab"}}' https://us11.api.mailchimp.com/3.0/lists/ant6308990/members/

此请求返回:

HTTP/1.1 401 Unauthorized
Server: nginx
Content-Type: application/problem+json; charset=utf-8
Content-Length: 210
Link:<https://us11.api.mailchimp.com/schema/3.0/ProblemDetailDocument.json>; rel="describedBy"
Date: Fri, 14 Aug 2015 17:22:05 GMT
Connection: close

{"type":"http://kb.mailchimp.com/api/error-docs/401-api-key-missing","title":"API Key Missing","status":401,"detail":"Your request did not include an API key.","instance":"17eb4090-13e4-47ff-aee1-ca62281fe547"}

我想知道如何获得授权。试图阅读API文档-简短。有人知道如何设计授权请求吗?

谢谢。

curl mailchimp
3个回答
0
投票

您可以使用cURL的--user参数,如MailChimp的API v3 documentation所示。


2
投票

这是v3中具有api键的PHP / cURL身份验证的基本代码

$username = "tcgumus";
   //it can be anything    
$password = "API KEY";    
   // create curl resource     
$ch = curl_init();      
    // set url      
curl_setopt($ch, CURLOPT_URL, "http://us10.api.mailchimp.com/3.0/"); 
    //make sure your dc is correct     
    //return the transfer as a string      
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");    
    // $output contains the output string     
$output = curl_exec($ch);     
    // close curl resource to free up system resources     
curl_close($ch);       
print_r($output);   

0
投票

请按照此处的步骤操作:

  1. 创建您的base64编码的api密钥:base64_encode(您的api用户名:api密钥)
  2. 在您的CURL请求中使用基本身份验证为
    
    curl -i -H "Content-Type: application/json" -H "Authorization:Basic your base64 encoded string" https://us11.api.mailchimp.com/3.0/
    
  3. 注意,您必须使用单词“ Basic”
  4. 因此,在您的所有curl请求中,添加身份验证标头以在进行其他任何请求之前对自己进行授权。因此,根据您的情况,请尝试以下

    
    curl -i -H "Content-Type: application/json" 
    -H "Content-Type: application/json"
    -H "Authorization:Basic your base64 encoded string"
    -d '{"apikey" :  "60dd1f3aaa977bf1zzza159yyye93exx-us11","email_address": "[email protected]","status":"subscribed",
    "merge_fields":{"FNAME":"Urist","LNAME":"McVankab"}}' https://us11.api.mailchimp.com/3.0/lists/ant6308990/members
© www.soinside.com 2019 - 2024. All rights reserved.