Qiita にAPIを使って投稿したいのですがうまくいきません。
どなたか御教授をお願いできませんでしょうか?
<?php
class QiitaApiV2 {
public $QiitaToken ;
public $BASE ;
function __construct($P=FALSE){
$this->QiitaToken = '????????????????????????????????????????' ;
$this->BASE = 'https://qiita.com' ;
}
function CallApi($json){
$url = $this->BASE . '/api/v2/items' ;
$ch = curl_init() ;
$headers = [
'Authorization: Bearer '. $this->QiitaToken,
'Content-type: application/json',
] ;
curl_setopt($ch,CURLOPT_URL,$url) ;
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST') ;
curl_setopt($ch,CURLOPT_POST,true) ;
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($json)) ;
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers) ;
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$payload = curl_exec($ch) ;
curl_close($ch) ;
return $payload ;
}
}
if($qiita = new QiitaApiV2()){
$json = [
'body' => '# Example',
'coediting' => false ,
'private' => false,
'tags' => [
[
'name' => 'PHP',
'versions' => ['8.2.1']
]
],
'title' => 'Example title',
'tweet' => false,
// 'organization_url_name' => 'qiita-inc', //エラーの原因箇所
'slide' => false ,
'id' => false ,
] ;
echo $qiita->CallApi($json) ;
}
実行結果
HTTP/2 404
date: Wed, 23 Aug 2023 07:51:25 GMT
content-type: application/json
server: nginx
rate-limit: 1000
rate-remaining: 992
rate-reset: 1692780154
vary: Origin
x-request-id: eb08ef99-008a-47f5-9668-517577209071
x-runtime: 0.131084
strict-transport-security: max-age=2592000
{"message":"Not found","type":"not_found"}