Skip to content

Instantly share code, notes, and snippets.

@fukaz55
Last active December 19, 2018 06:08
Show Gist options
  • Save fukaz55/b733f36df552f9f6206189f55c92e16f to your computer and use it in GitHub Desktop.
Save fukaz55/b733f36df552f9f6206189f55c92e16f to your computer and use it in GitHub Desktop.
track-o-botに戦歴をPOSTするテストスクリプト
<?php
/* お手本:https://gist.github.com/stevschmid/120adcbc5f1f7cb31bc5 */
$api = 'https://trackobot.com/profile/results.json';
$username = 'username';
$token = 'YOUR_API_TOKEN';
$headers = array(
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode("{$username}:{$token}") /* BASIC認証用のヘッダを生成 */
);
$data = json_encode(
array(
'result' => array(
'hero' => "Priest", /* ユーザーのヒーロー名 */
'opponent' => "Druid", /* 対戦相手のヒーロー名 */
'mode'=> "ranked", /* casual/ranked/arena/friendly */
'rank' => 25, /* ランク帯 1-25 */
'legend' => null, /* レジェンド帯での順位 */
'coin' => false, /* 後攻ならtrue */
'win' => true, /* 買ったらtrue, 負けたらfalse */
'added' => date('c'), /* ゲームの行われた日時をISO8601形式で指定 */
'note' => 'Basic Post Test' /* track-o-botの戦歴で表示されるコメント */
),
'username' => $username,
'token' => $token
)
);
$options = array('http' =>
array(
'method' => 'POST',
'header' => implode("\r\n", $headers),
'ignore_errors' => true,
'content' => $data,
)
);
$result = file_get_contents($api, false, stream_context_create($options));
echo "\n---\n";
echo $result;
echo "\n---\n";
print_r($http_response_header);
echo "\n---\n";
?>
@xiaohk
Copy link

xiaohk commented Dec 19, 2018

Hello, I have tried your method using Postman, but the result is 404.

Does it still work for you?

@xiaohk
Copy link

xiaohk commented Dec 19, 2018

Oh, its working now.

I have to set the url to https://trackobot.com/profile/results.json instead of https://trackobot.com/profile/history.json.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment