LoginSignup
11

More than 5 years have passed since last update.

Twitterでいいね爆撃

Last updated at Posted at 2016-06-22

動機

ちょっとした悪戯

前提

  • 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);
}

あんまりやり過ぎると怒られるよ?

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
11