動機
ちょっとした悪戯
前提
- Twitterアカウントの取得
- Twitter API Keyの取得
認証
面倒くさい認証部分はライブラリを使う
インストールはComposerでOK
$ composer require abraham/twitteroauth
爆撃
like.php
<?php
// OAuthライブラリを読み込む
require_once __DIR__ . '/vendor/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
// 認証情報
$consumerKey = 'xxxxxxxxxx';
$consumerSecret = 'xxxxxxxxxx';
$accessToken = 'xxxxxxxxxx';
$accessTokenSecret = 'xxxxxxxxxx';
// 接続
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
// タイムラインを取得
// 対象のユーザIDと取得するツイート数を指定
// スクリーンネームからユーザIDを調べるWebサイト => https://syncer.jp/twitter-screenname-userid-converter
$timeline = $connection->get('statuses/user_timeline', ['user_id' => '526471763', 'count' => 100]);
// 連想配列に変換
$timeline = json_decode(json_encode($timeline), true);
// ツイートにいいね
foreach ($timeline as $t) {
$connection->post('favorites/create', ['id' => $t['id']]);
sleep(1);
}
あんまりやり過ぎると怒られるよ?