php GuzzleでQiita APIv2で投稿をPOSTする小さなサンプル
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php GuzzleでQiita APIv2で投稿をPOSTする小さなサンプル相关的知识,希望对你有一定的参考价值。
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
class Qiita
{
private $client;
private $accessToken;
private $headers;
const BASEURL = "https://qiita.com/api/v2/";
public function __construct(string $accessToken){
$this->accessToken = $accessToken;
$this->headers = [
"Authorization" => "Bearer ".$accessToken,
"Content-Type" => "application/json"
];
$this->client = new Client([
"base_uri" => self::BASEURL,
"headers" => $this->headers
]);
}
public function postItem(array $param){
$response = $this->client->request("POST", "items", [
GuzzleHttp\RequestOptions::JSON => $param
]);
return $response;
}
}
$qiita = new Qiita("xxxxxxxxxxxxxxxxxxxx");
//↓はパラメータなので適当に書き換える
$param = ["body" => "TEST from APIv2",
"gist" => false,
"private" => true,
"tags" => [["name" => "qiita", "versions"=>["2"]]],
"title"=>"TEST from API2",
"tweet" => false];
$result = $qiita->postItem($param);
以上是关于php GuzzleでQiita APIv2で投稿をPOSTする小さなサンプル的主要内容,如果未能解决你的问题,请参考以下文章
php 投稿时に自动でタクソノミー登录
text DockerでPHP环境参考:https://qiita.com/ka2uk/items/d44d4688a0f122b5fdaa
php WordPressの管理画面の「表示设定」で「1ページに表示する最大投稿数」の値を取得する
text Gitで致命:远程起源已经存在。が出るときref:https://qiita.com/_bns/items/c3f9559890b5205761b8
javascript redux-observableで作ったintervalのobservableを热模块更换で止まるようにするref:https://qiita.com/terrierscript
csharp C#でDozensのDNSレコードを操作するref:http://qiita.com/nakaji/items/008090c0fc8173afce53