之前我没有使用过API,我正在尝试使用PHP Curl连接到Yesmail API,但我收到错误{"fault":{"faultstring":"Failed to resolve API Key variable null","detail":{"errorcode":"steps.oauth.v2.FailedToResolveAPIKey"}}}
Yesmail API文档 - https://developer.yesmail.com/yesmail-api-overview
示例代码:
//CURL
$apiKey = 'xxxxxxxx';
$url = 'https://api.yesmail.com/connect/my/api' .$apiKey;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
print_r(json_decode($response, true));
任何想法我可能做错了什么?
答案 0 :(得分:1)
您发送API凭据的方式是错误的。你必须这样做:
$api_user = "YOU_KNOW";
$api_key = "YOU_KNOW";
$url = "https://api.yesmail.com/v2/subscribers";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Api-User: $api_user", "Api-Key: $api_key"));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);