Advertisement
Guest User

Untitled

a guest
Dec 4th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'TwistOAuth.php';
  4.  
  5. // APIキー設定
  6. $ck = '';
  7. $cs = '';
  8. $ot = '';
  9. $os = '';
  10.  
  11. // リクエスト設定
  12. $slug              = '';   // リスト名
  13. $owner_screen_name = '';   // 所持者のスクリーンネーム
  14. $count             = 30;   // フォロワーの最新何件を対象にするか
  15. $stringify_ids     = true; // True固定
  16.  
  17. // テキストとしてデータを表示
  18. header('Content-Type: text/plain; charset=utf-8');
  19.  
  20. try {
  21.  
  22.     // TwistOAuthのインスタンス生成
  23.     $to = new TwistOAuth($ck, $cs, $ot, $os);
  24.    
  25.     // フォロワーID一覧の取得
  26.     $ids = $to->get('followers/ids', compact('count', 'stringify_ids'))->ids;
  27.    
  28.     // リスト追加のためのcURLリソースの生成
  29.     $curls = [];
  30.     foreach ($ids as $i => $id) {
  31.         $curls[$i] = $to->curlPost('lists/members/create', compact('user_id', 'owner_screen_name', 'slug'));
  32.     }
  33.    
  34.     // 並列実行して結果表示
  35.     foreach ($to->curlMultiExec($curls) as $i => $response) {
  36.         if ($response instanceof stdClass) {
  37.             echo "{$ids[$i]}: 成功\n";
  38.         } else {
  39.             echo "{$ids[$i]}: 失敗({$response->getMessage()})\n";
  40.         }
  41.     }
  42.    
  43. } catch (TwistException $e) {
  44.    
  45.     // フォロワー一覧取得失敗時など
  46.     echo 'エラー: ' . $e->getMessage();
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement