Berbagi Artikel-Artikel Unik Dan Bermutu

Blog Archive

Copyright © 2015 Artikel TopNews | . Powered by Blogger.

Labels

ads3

tag

Top Artikel

ads2

ads

iklan

Auto Retweet & Favorite di Twitter


Seperti biasanya, agan butuh twitteroauth library dulu untuk auth di twitternya, klo yg males download bisa langsung ambil filenya di sini

http://pastebin.com/5XsgH8p2

http://pastebin.com/AusVevKV

simpan dlm 1 folder semua tuh file. trus bikin file trus isi script kya gini:
<?php
//thank to devilzc0de.org and api twitter
set_time_limit(0);
class rieqyns13{
public $consumer_key;
public $consumer_secret;
public $access_token;
public $access_token_secret;
public $count_search;
public $keyword;
public $fav_tweet;
public $re_tweet;
function bot(){
require_once("twitteroauth.php");
$con = new TwitterOAuth($this->consumer_key, $this->consumer_secret, $this->access_token, $this->access_token_secret);
echo "[+]Mencari {$this->count_search} tweet dgn keyword: ".$this->keyword."n";
$data_ = $con->get('search/tweets', array("q"=> urlencode($this->keyword), "count"=> $this->count_search));
if(empty($data_->statuses)){
echo "Tidak ada hasil dgn keyword ".$this->keyword;
exit;
}
foreach($data_->statuses as $data){
echo "[+]Mencoba menangkap tweet dari ".$data->user->screen_name.": ".$data->text."n";
if($this->re_tweet==true){
$post = $con->post('statuses/retweet/'.$data->id_str);
if(!empty($post->errors)){
if(isset($post->errors[0]->message)) $error = $post->errors[0]->message;
elseif(isset($post->errors)) $error = $post->errors;
else $error = "Unknow error";
$status = "Error -> ".$error."n";
}else{
$status = "Sukses -> ".$post->id_str."n";
}
echo "[+]Retweet: ".$status;
}
if($this->fav_tweet==true){
$post = $con->post('favorites/create', array("id"=>$data->id_str));
if(!empty($post->errors)){
if(isset($post->errors[0]->message)) $error = $post->errors[0]->message;
elseif(isset($post->errors)) $error = $post->errors;
else $error = "Unknow error";
$status = "Error -> ".$error."n";
}else{
$status = "Sukses -> ".$post->id_str."n";
}
echo "[+]Favorite: ".$status;
}
}
}
}
?>

sorry gan, pke OOP trus. soalnya dah kebiasaan
setelah disave, buat file lagi trus ksih script:

<?php
require_once("twitterbot.php");
$gay = new rieqyns13;
$gay->keyword="hacker maho"; //kata kunci tweet yg ingin dicari
$gay->count_search=13; //jumlah tweet yg ingin dicari
$gay->fav_tweet=true; //fitur favorite tweet, TRUE=aktif, FALSE=tidak aktif
$gay->re_tweet=true; //fitur re tweet, TRUE=aktif, FALSE=tidak aktif
$gay->consumer_key="***********";
$gay->consumer_secret="***********";
$gay->access_token="***********";
$gay->access_token_secret="***********";
$gay->bot();
?>


jika path sudah disetting ke direktori PHP, tinggal dirun pke cmd
php twit.php


ntar gini proses runningnya



cek twitter, jika ada kya gini berarti scriptnya sukses

klo mw diatur lewat cron job, atur sendiri
o..ya, ane hampir lupa. jgn lupa application settings di app twitternya nya ganti ke Read and Write. cranya: My Applications->Settings->di Application type pilih Read and Write

sekian dan trima kasih



Tag : PHP, Twitter
0 Komentar untuk "Auto Retweet & Favorite di Twitter"
Back To Top