0
1

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.

ツイッターAPIの情報取得を簡単に

Last updated at Posted at 2018-03-05

ツイッターのAPIを取得して出力するコードを最小で

まずTwistOAuth をインストール。
https://github.com/mpyw/TwistOAuth

ツイッターマネジメントってやつに登録
https://apps.twitter.com
そこからconsumer_key, consumer_secret, access_token, access_token_secretの4つを取得します。

次にTwistOAuthフォルダのbuildフォルダにtwi.phpを作成

twi.php
//TwistOAuthダウンロード
//buildのフォルダにファイル作成
require 'TwistOAuth.phar';

//自分のtwitter developperの情報4つ入れる
$consumer_key = '自分のキー';
$consumer_secret = '自分のキーその2';
$access_token = '自分のキーその3';
$access_token_secret = '自分のキーその4';

//インスタンス化
$cone = new TwistOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);

//取得の条件を入れる
$tu = ['q'=>'ロックバンド','count'=>'20'];
$tubu = $cone->get('search/tweets', $tu)->statuses;

//繰り返し処理で取り出す
foreach($tubu as $ok){
	print $ok->text;
	print "<br>";
}

ロックバンドってキーワードを含む投稿を20件取り出します

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?