前提
https://twitteroauth.com/
のドキュメントを参考にcomposerからインストール
https://developer.twitter.com/
から申請しAPIキーを取得
(最低限の)前提知識
スクリーンネームとユーザーID
・スクリーンネーム -> @hogehoge 的なID,いつでも変更できる
・ユーザーID -> 絶対に変えられないID ※今回はユーザーIDを利用する
・API(アプリケーションインターフェース) -> 認可サーバーのID
・アクセストークン ->twitterが出した「ここまでの範囲なら利用していいよ!」ってやつ
詳しくはhttps://booth.pm/ja/items/1296585
の書籍を参考にしてください
test.php
<?php
require "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth as TwitterOAuth;
$consumerKey = "#########";
//APIキーを記述
$consumerSecret = "######################################";
//シークレットAPIキーを記述
$accessToken = "############################################";
//自分もしくは他人のアクセストークン
$accessTokenSecret = "###########################################";
//自分もしくは他人のシークレットアクセストークン
$twitter = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
$id ='################';
//いいね、RT対象のstatusIDを記述
$user_id ='#####################';
//フォローする対象のユーザーIDを記述
$retweet = $twitter->post('statuses/retweet',['id' => $id]);
//RTする
$favorites = $twitter->post('favorites/create', ['id' => $id]);
//いいねする
$follow = $twitter->post('friendships/create', ['user_id'=> $user_id]);
// フォローする