したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | |
レス数が900を超えています。1000を超えると投稿できなくなるよ。

TwitterBotPHP質問スレ

501名無しさん:2010/10/08(金) 14:53:45
// twitteroauth.phpを読み込む。パスはあなたが置いた適切な場所に変更してください
require_once("twitteroauth/twitteroauth.php");

//OAuthキーをそれぞれ入力
$consumer_key = "";
$consumer_secret = "";
$access_token = "";
$access_token_secret = "";

//最後に読み込んだリプライを保存するtxtファイル(同じフォルダに保存、パーミッションを書き込み可に)
$filename = "tenki.txt";
$host = "http://twitter.com/statuses/mentions.xml"; //返信一覧


$fp = @fopen($filename,'rb') or die("ファイルが開けません");
flock($fp, LOCK_EX);
$line = fgets($fp, 64);
fclose($fp);

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


//保存しておいたステータスid取得。このid以降の返信を読み込む。なかったり読み込めなかったら最新1件
if(!empty($line)){
$req = $to->OAuthRequest($host,"GET",array("since_id"=>$line));
}
else{
$req = $to->OAuthRequest($host,"GET",array("count"=>"1"));
}


//XML文字列をオブジェクトに代入する
$XML = simplexml_load_string($req);

//フレンドリストのオブジェクト作成
$host = "http://twitter.com/friends/ids.xml";
$req = $to->OAuthRequest($host,"GET",array());
$friends = simplexml_load_string($req);
$friendslist = array();
foreach($friends->id as $item){
$friendslist[] = (String)$item;
}


//順に返信
$i = count($XML)-1;
$j = 0;
while($i >= $j) {
$var = $XML->status[$i]->text;
$com = ereg_replace("\@$username", "", $var);
$reply_name = $XML->status[$i]->user->screen_name;
$name = $XML->status[$i]->user->name;
$id = $XML->status[$i]->id;

//ゴチャゴチャするので、返信のセリフ組み合わせはユーザー定義関数で。
$message = serif($reply_name,$name,$com,$id);
//そのままポストの関数へ…
if($message){
$result = $to->OAuthRequest("https://twitter.com/statuses/update.xml","POST",array("status"=>$message,"in_reply_to_status_id"=>"$id"));
print $result;
}
$i--;
}

//最終発言リプライのidを保存してる部分。先頭を調べて…
$string = $XML->status[0]->id;
//空じゃなかったら書き込み
if(!empty($string)){
$dat = (string)$string;
file_put_contents($filename,$dat,LOCK_EX);
}
//これでメインの処理は終わり


//セリフ生成のユーザー定義関数
function serif($reply_name,$name,$com,$id){

$break_flag = false;
$today = date("Y/m/d l H:i:s");//デバッグ用の日付表示(なくてよい)


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板