2

Apple News API の助けを借りて接続できますが、json 形式でデータを送信できません。私のコードは以下です。しかし、jsonファイルを添付しようとすると. 署名失敗メッセージが表示されます。

    <?php
$channel_id = 'xxxxxxxxxxxxxxxxxx';
$api_key_id = 'xxxxxxxxxxxxxxx';
$api_key_secret = 'xxxxxxxxxxxxxxxx';
// use the correct values above    
$data = file_get_contents('article.json');
$Content_type="application/json";

$url = 'https://news-api.apple.com/channels/'.$channel_id;
$date = gmdate('Y-m-d\TH:i:s\Z');
$canonical_request = 'GET'.$url.$date.$Content_type;
$key = base64_decode($api_key_secret);
$hashed = hash_hmac('sha256', $canonical_request,$key,true);
$signature = base64_encode($hashed);
echo $signature;
//curl options
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);

$headers = array();
$headers[] = "Authorization: HHMAC; key={$api_key_id}; signature={$signature}; date={$date}";

$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_POST, true);

//curl_setopt( $ch, CURLOPT_POSTFIELDS, $data);

//get result
$server_output = curl_exec ($ch);
curl_close ($ch);

print_r(json_decode($server_output));

?>
4

1 に答える 1