Last active
August 29, 2015 14:10
-
-
Save nknskn/ef8b1ba31f8b734b8e41 to your computer and use it in GitHub Desktop.
twitter_list_OR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once("twitteroauth/twitteroauth.php"); | |
$consumerKey = "<ご自分のコンシューマキーをどうぞ>"; | |
$consumerSecret = "ご自分の以下略"; | |
$accessToken = "ご自分(ry"; | |
$accessTokenSecret = "(ry"; | |
$TwiOAuth = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); | |
$url_ListCreate = 'https://api.twitter.com/1.1/lists/create.json'; | |
$url_Tweet = 'https://api.twitter.com/1.1/statuses/update.json'; | |
$url_ListMemberGet = 'https://api.twitter.com/1.1/lists/members.json'; | |
$url_ListMemberAdd = 'https://api.twitter.com/1.1/lists/members/create.json'; | |
$list_name = "hogefuga"; | |
$list_mode = "public" or "private"; | |
$list_owner_screen_name = "ご自分のアカウントをどうぞ 例:nknskn"; | |
$list_req = $TwiOAuth->post($url_ListCreate,array("name" => $list_name,"mode" => $list_mode)); | |
if (isset($list_req->{'errors'}) && $list_req->{'errors'} != '') { | |
echo "error<br>"; | |
var_dump($list_req); //エラーですよ、アザゼルさん | |
}else { | |
echo "create "+$list_name+"<br>"; | |
$list_id1 = ''; // 結合したいlist_id 1 | |
$list_id2 = ''; // 結合したいlist_id 2 | |
$cursor = -1; | |
$count=1; | |
//list_id1内のユーザを突っ込む | |
while ($cursor!=0){ | |
$list_copy = $TwiOAuth->get($url_ListMemberGet, array('list_id' => $list_id1,"cursor"=>$cursor)); | |
foreach($list_copy->users as $oUser){ | |
echo $count."ユーザー名:(".$oUser->name.")<br/>\n"; | |
$new_member = $TwiOAuth->post($url_ListMemberAdd,array("slug"=>$list_name, | |
"owner_screen_name"=>$list_owner_screen_name,"user_id"=>$oUser->id)); | |
if(isset($new_member->{'errors'}) && $new_member->{'errors'} != ''){ | |
echo "error"; | |
$count=0; | |
break; | |
} | |
sleep(2); | |
} | |
if ($count===0) break; | |
$cursor = $list_copy->next_cursor; | |
} | |
//list_id2内のユーザを突っ込む | |
if ($count===1) { | |
$cursor = -1; | |
while ($cursor!=0){ | |
$list_copy = $TwiOAuth->get($url_ListMemberGet, array('list_id' => $list_id2,"cursor"=>$cursor)); | |
foreach($list_copy->users as $oUser){ | |
echo $count."ユーザー名:(".$oUser->name.")<br/>\n"; | |
$new_member = $TwiOAuth->post($url_ListMemberAdd,array("slug"=>$list_name, | |
"owner_screen_name"=>$list_owner_screen_name,"user_id"=>$oUser->id)); | |
if(isset($new_member->{'errors'}) && $new_member->{'errors'} != ''){ | |
echo "error"; | |
$count=0; | |
break; | |
} | |
sleep(2); | |
} | |
if ($count===0) break; | |
$cursor = $list_copy->next_cursor; | |
} | |
} | |
echo "<br>done."; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment