9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPでMastodonのStreaming APIを受信する。

Last updated at Posted at 2017-04-17

はじめに

MastodonのStreaming API、簡単に受信できたので 共有します。

PHPのコード

やっていることは受信してvar_dump出力しているだけです。

stream.php
<?php

$fp = fsockopen('ssl://example.com', 443, $errno, $errstr, 5);

const ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

$req = ['GET /api/v1/streaming/public HTTP/1.1',
		'Host: pawoo.net',
		'User-Agent: bot20170416',
		'Authorization: Bearer '.ACCESS_TOKEN,
		];

// GETリクエストを送信
fwrite($fp, implode($req, "\r\n")."\r\n"."\r\n" );

while (!feof($fp)) {
	$read = fgets($fp);
	var_dump($read);
}

fclose($fp);

こちらの記事(MastodonのAPIを使ってみた - Qiita)を参考にして、 ACCESS_TOKENを取得します。取得できたら、ACCESS_TOKENのxxxxxxを書き換えてください。

やらなければならないこと。

  • エラー処理
  • 取得したあとの処理
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?