プログラムの勉強で自動売買のソフトを作ろうと試行錯誤中です。
参考にしたURL
https://www.quoine.com/api/?lang=ja
http://kappazu.com/2017/11/24/%E4%BB%AE%E6%83%B3%E9%80%9A%E8%B2%A8%E8%87%AA%E5%8B%95%E5%A3%B2%E8%B2%B7%E5%85%A5%E9%96%80%E3%80%80python%E3%81%A7quoinex-api%E3%81%A6%E3%81%99%E3%81%A8%E2%91%A0/
自力で色々検索してここまでは出来たのですがエラーで解決できそうにないので教えていただきたいのです。
Warning: hash_hmac() expects parameter 2 to be string, array given in /home/ubuntu/workspace/quoinex_balance.php on line 30 Call Stack: 0.0014 236360 1. {main}() /home/ubuntu/workspace/quoinex_balance.php:0 0.0015 238576 2. hash_hmac() /home/ubuntu/workspace/quoinex_balance.php:30 Warning: file_get_contents(https://api.quoine.com/accounts/balance): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in /home/ubuntu/workspace/quoinex_balance.php on line 47 Call Stack: 0.0014 236360 1. {main}() /home/ubuntu/workspace/quoinex_balance.php:0 0.0088 241384 2. file_get_contents() /home/ubuntu/workspace/quoinex_balance.php:47
line 30 のところが$sign = hash_hmac('HS256', $text, $secret);の場所なので
ここが間違っているのかな?とは予測までは出来たのですが
そこからどう解決していいか?が解らないので解決方法など教えて頂けると幸いです。
※なるべくはClassや外部のスクリプトなどを使わずに作成したいと思っています。
追記
さらに自分なりに調べた結果
expects parameter 2 to be stringの部分はhash hmac()がString型にしなければならないという事?と思ったので
$text = array(
'path:' .$order_url,
'nonce:' .$timestamp,
'token_id:' .$key,
);
を
$text =json_encode( array(
'path:' .$order_url,
'nonce:' .$timestamp,
'token_id:' .$key,
));
に、変更したところエラーがUnknown hashing algorithm: HS256に変化しました。
hash hmac()はHS256が使えないという事かな??
追記その2
>hash hmac()はHS256が使えないという事かな??
ご指摘をいただきましてhash-hmacはHS256が使えないので
sha1を指定しなおしたらこの部分のエラーは解消しました!!
しかし
failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
file_get_contents()の部分のエラーは解消出来ず
残念ながら接続できませんでした。
引き続き自分でも調べてみますがご存知の方がいらっしゃいましたらよろしくお願いします。
※なるべくはClassや外部のスクリプトなどを使わずに作成したいと思っています。
php
1<?php 2//API取得して入力 3$key = '*****'; 4$secret = '******'; 5 6// URL 7$base_url = 'https://api.quoine.com'; 8$order_url = '/accounts/balance'; 9$url = $base_url . $order_url; 10$version = '2'; 11 12 13//ヘッダー 14$timestamp = time() . substr(microtime(), 2, 3); 15//$method = 'POST'; 16$text = array( 17 'path:' .$order_url, 18 'nonce:' .$timestamp, 19 'token_id:' .$key, 20 ); 21$sign = hash_hmac('HS256', $text, $secret); 22 23$header = array( 24 'X-Quoine-API-Version:' . $version, 25 'X-Quoine-Auth:' . $sign, 26 'Content-Type:application/json', 27); 28$context = stream_context_create(array( 29 'http' => array( 30 'method' => $method, 31 'header' => implode(PHP_EOL, $header), 32 'content' => $body, 33 ) 34)); 35 36// API呼び出し 37$response = file_get_contents($url, false, $context); 38$result = json_decode($response, true); 39print_r($result);

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/03 19:22
2018/02/03 20:18