ある特定のユーザーをフォローしたい場合の最も簡単なサンプルプログラムです。twitteroauth.php を使用しています。
以下は私のIDをフォローする場合の例です。
1 2 3 4 5 6 7 8 9 10 |
<?php require_once("twitteroauth.php"); $consumer_key = "ComsumerKey"; $consumer_secret = "ComsumerSecret"; $access_token = "AccessToken"; $access_token_secret = "AccessTokenSecret"; $to = new TwitterOAuth($consumer_key,$consumer_secret,$access_token,$access_token_secret); $req = $to->OAuthRequest("http://api.twitter.com/1/friendships/create/suzuki86.xml","POST",""); ?> |
「http://api.twitter.com/1/friendships/create/フォローしたいアカウントのID.xml」にPOSTでリクエストを送信します。リムーブ(unfollow)したい場合は「http://api.twitter.com/1/friendships/destroy/フォローしたいアカウントのID.xml」にPOSTでリクエストを送信します。つまりは 8 行目の「create」を「destroy」に変えます。
[…] This post was mentioned on Twitter by 新居田 誠, シラサカショウ. シラサカショウ said: 「とっても役に立ちましたありがとうございました」[B!]Twitter APIを利用して特定のユーザーをフォロー・リムーブする « ITScrapBook http://ow.ly/2O6FF […]