[通常ポスト]

<?php
// twitteroauth.phpを読み込む
require_once("twitteroauth.php");

$consumer_key = "";
$consumer_secret = "";
$access_token = "";
$access_token_secret = "";

// OAuthオブジェクト生成
$to = new TwitterOAuth($consumer_key,$consumer_secret,$access_token,$access_token_secret);

$mes['rand'] = array("1","2","3","4","5");//通常post
$mes['morning'] = array("1","2","3","4","5");//起床post
$mes['noon'] = array("1","2","3","4","5");//昼post
$mes['night'] = array("1","2","3","4","5");//就寝post
$now_g = date('G');
$now_i = date('i');
if(($now_g > '1') && ($now_g < '7') ){//2〜6時の投稿を禁止する
	$now_g = 'sleep';
}

switch(true){
	case $now_g == 'sleep' :
	$plist = array();
	break;
	case ($now_g == '1')&&($now_i >= '30') :
	$plist = $mes['night'];//1時かつ30分以降の時に'night'の台詞を投稿する
	break;
	case ($now_g == '12') :
	$plist = $mes['noon'];//12時に'noon'の台詞を投稿する
	break;
	case ($now_g == '7')&&($now_i <= '30') :
	$plist = $mes['morning'];//7時かつ30分未満の時に'morning'の台詞を投稿する
	break;
	default :
	$plist = $mes['rand'];//それ以外の時間の時に通常postをする
	break;
};

//投稿するメッセージを決定
if(! empty($plist)){
	$key = array_rand($plist);
	$post = $plist[$key];
}

// TwitterへPOSTする。パラメーターは配列に格納する
$req = $to->OAuthRequest("https://api.twitter.com/1.1/statuses/update.json","POST",array("status"=>"$post"));

header("Content-Type: application/json");
echo $req;
?>

一覧に戻る