}
//約1時間ごとに取得を繰り返す
for ($i = 0; $i < $repeat; $i++) {
    //ツイート検索パラメータの設定
    $params = array("q" => "filter:images since:2016-1-11 until:2016-1-12", "lang" => "ja", "count" => 50, "include_entities" => true, "result_type" => "recent");
    //ツイートIDの指定を配列に追加
    if ($confirm == false) {
        $params += array("max_id" => $tweet_id . "100000000000");
    }
    //2回目以降は約1時間前のツイートIDにする
    $tweet_id = $tweet_id - 15;
    //リクエスト回数
    $request_number = 1;
    for ($j = 0; $j < $request_number; $j++) {
        //検索結果の取得($tweets_objはJSONの検索結果が入る)
        $tweets_obj = $connection->OAuthRequest('https://api.twitter.com/1.1/search/tweets.json', 'GET', $params);
        if ($tweets_obj) {
            //検索結果をjson_decodeで連想配列に変換
            $tweets_arr = json_decode($tweets_obj, true);
            //画像のURLを取得
            foreach ($tweets_arr['statuses'] as $statuses) {
                if (isset($statuses['entities']['media'][0]['media_url'])) {
                    $photoURL = $statuses['entities']['media'][0]['media_url'];
                    //APIの日時に合わせる
                    date_default_timezone_set('Europe/London');
                    //投稿日時を取得
                    $postedDatetime = date('Y-m-d H:i:s', strtotime($tweets_arr['statuses'][0]['created_at']));
                    //DBに画像のURLと投稿日時を追加
                    if ($db == true) {
                        $result = insert_photo($photoURL, $postedDatetime, $snsID);
                    }