PHP JSON Post格式?
我正在努力完成从enfmp标记器向echonest服务器发送json数据的简单操作 PHP代码PHP JSON Post格式?,php,json,curl,Php,Json,Curl,我正在努力完成从enfmp标记器向echonest服务器发送json数据的简单操作 PHP代码 $file =file_get_contents('./test.json'); $jsondecode = json_decode($file,true ); foreach($jsondecode as $puffer) { $result = $puffer['code']; } $post = array( "api_key"=>"=MYAPIKEY", "version"=&g
$file =file_get_contents('./test.json');
$jsondecode = json_decode($file,true );
foreach($jsondecode as $puffer) {
$result = $puffer['code'];
}
$post = array(
"api_key"=>"=MYAPIKEY",
"version"=>"=3.15",
"code"=>"=$result",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "http://developer.echonest.com/api/v4/song/identify");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$json_response = curl_exec($ch);
$response = json_decode($json_response, true);
答案是
["response"]=>
array(1) {
["status"]=>
array(3) {
["version"]=>
string(3) "4.2"
["code"]=>
int(1)
["message"]=>
string(22) "1|Invalid key: Unknown"
}
}
}
API密钥工作正常。
有人能看一下代码并给我一些提示或示例吗
问候语:)您的代码没有问题。根据您收到的回复信息判断,我认为服务部门希望您以其他方式发送密钥。可能是作为GET参数,而不是作为
应用程序/x-www-form-urlencoded
,或者可能使用的名称不是“api_key”
。几乎可以确认,api\u key
需要是一个GET参数。。。