Пример #1
0
 function main($option = null)
 {
     $con;
     $user;
     $consumer_key;
     $consumer_secret;
     $access_token;
     $access_token_secret;
     try {
         Util::open_Log();
         $con = Util::getDbConnection();
         $sql = "SELECT user,\n                     consumer_key,\n                     consumer_secret,\n                     access_token,\n                     access_token_secret\n              FROM\n                     twitter_users\n              WHERE\n                     No = 0";
         $query = $con->prepare($sql);
         $query->execute();
         foreach ($query->fetchAll() as $row) {
             $user = $row['user'];
             $consumer_key = $row['consumer_key'];
             $consumer_secret = $row['consumer_secret'];
             $access_token = $row['access_token'];
             $access_token_secret = $row['access_token_secret'];
         }
         $Bot = new Twitter_Bot($user, $consumer_key, $consumer_secret, $access_token, $access_token_secret);
         $list = Util::getTweetLists();
         $max = count($list);
         // latest
         if (strcmp($option, 'last') === 0) {
             $messages = $list[$max - 1];
             // specify
         } else {
             if (ctype_digit($option) && $option < $max) {
                 $messages = $list[$option];
                 // random
             } else {
                 if (shuffle($list)) {
                     $messages = $list[0];
                 }
             }
         }
         for ($i = 0; $i < TRY_MAX; $i++) {
             // ツイート
             $result_code = $Bot->Post($messages[0]);
             if ($result_code == 0) {
                 break;
             }
         }
     } catch (PDOException $e) {
         print $e->getMessage() . "\n";
         Util::write_Log("Caught Exception -> " . $e);
     } catch (Exception $e) {
         print $e->getMessage() . "\n";
         Util::write_Log("Caught Exception -> " . $e);
     } finally {
         Util::close_Log();
     }
 }
Пример #2
0
    $query = $con->prepare($sql);
    $query->execute();
    foreach ($query->fetchAll() as $row) {
        $user = $row['user'];
        $consumer_key = $row['consumer_key'];
        $consumer_secret = $row['consumer_secret'];
        $access_token = $row['access_token'];
        $access_token_secret = $row['access_token_secret'];
    }
} catch (Exception $e) {
    print "Caught Exception -> {$e}\n";
    print "Message -> {$e}.getMessage()\n";
} finally {
}
// オブジェクト生成
$Bot = new Twitter_Bot($user, $consumer_key, $consumer_secret, $access_token, $access_token_secret);
$sid = null;
$since_id = null;
$min = date("i");
//print("$min\n");
try {
    // データファイルを空にする
    $Bot->Clear_data("Tweet");
    // 以下通常のTL取得
    $since_id = $Bot->Get_data("Since");
    // 最後に取得した呟きのID
    $Bot->Clear_data("Since");
    //print_r($since_id);
    //$timeline = $Bot->Get_TL("home_timeline", $since_id, 300); // タイムラインの取得
    //$timeline = $Bot->Get_TL("user_timeline", $since_id, 300); // タイムラインの取得
    $timeline = $Bot->Get_TL("mentions_timeline", $since_id);