Github v3 API を使用し、JSON を投稿してプロファイル (またはその他の呼び出し) を更新し、Github から次の応答を取得しようとしています。
Array
(
[message] => Body should be a JSON Hash
)
API ドキュメントの関連ページを確認しました: http://developer.github.com/v3/users/
そして、このページ: POST/PATCH をカバーするhttp://developer.github.com/v3/#http-verbs
これが私が使用しているコードです
$data = array("bio" => "This is my bio" );
$data_string = json_encode($data);
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,1);
curl_setopt($ch, CURLOPT_USERPWD, "USERNAME:PASSWORD");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
$result = json_decode(curl('https://api.github.com/user'),true);
CURLOPT_CUSTOMREQUEST
as 'POST'
andも試しまし'PATCH'
たが、両方で同じエラー応答が得られました。
データを API に投稿するための正しい方向を教えてもらえますか?