• Silahkan bergabung dengan chat kami di Telegram group kami di N3Forum - https://t.me/n3forum
  • Welcome to the Nyit-Nyit.Net - N3 forum! This is a forum where offline-online gamers, programmers and reverser community can share, learn, communicate and interact, offer services, sell and buy game mods, hacks, cracks and cheats related, including for iOS and Android.

    If you're a pro-gamer or a programmer or a reverser, we would like to invite you to Sign Up and Log In on our website. Make sure to read the rules and abide by it, to ensure a fair and enjoyable user experience for everyone.

RNDC [RNDC] Twitter Periodic Update Avatar using PHP

dono

3 SMP
STAFF N3
Tukang Sapu
[float='left']resize.jpg [/float] Tulisan ini hanya sekedar proof-of-concept sederhana mengenai cara mengubah profile picture akun twitter dalam rentang waktu tertentu menggunakan library tweepy.

Langkah-langkah

Untuk mengganti profile picture akun twitter, kita dapat menggunakan API update_profile_image.
Dan pada library tweepy, kita akan menggunakan fungsi update_profile_image dengan memberikan satu parameter berupa path dari file gambar yang akan dijadikan profile picture. Untuk mengatur jadwal pergantian profile picture, kita memanfaatkan library time.

Berikut ini adalah listing dari script yang akan digunakan:
Code:
#!/bin/env python
import time
import glob
import tweepy

CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''

if __name__ == '__main__':
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

while True:
for f in glob.glob("./pic/*"):
print "[*] Using '%s' as new profile image" % f
api.update_profile_image(f)
time.sleep(15 * 60)
Keterangan dari tiap baris script di atas adalah sebagai berikut:
  • Pada baris ke-6 sampai ke-9, adalah variabel untuk OAuth berupa consumer key, consumer secret, access token key dan access token secret.
  • Baris 12 hingga 14 melakukan setup OAuth.
  • Baris ke-16 merupakan infinite loop untuk pergantian profile picture.
  • Baris ke-17 fungsinya adalah melakukan globbing untuk membuat daftar gambar yang akan digunakan sebagai profile picture yang ditempatkan pada sub direktori pic dan akan diproses satu per satu menggunakan variabel f.
  • Baris ke-18 fungsinya menampilkan informasi mengenai file apa yang saat ini akan digunakan sebagai profile picture.
  • Baris ke-19 merupakan inti dari script ini, yaitu melakukan update profile picture ke twitter.
  • Baris ke-20 merupakan timer sederhana yang akan mengulangi proses pergantian profile picture setiap 15 menit (15 * 60) detik.
Script tersebut jika dijalankan maka tampilannya kurang lebih akan seperti ini:

Code:
$ ./twpic.py
[*] Using './pic/01.png' as new profile image
[*] Using './pic/02.jpg' as new profile image
Demikian proof-of-concept sederhana ini, semoga bermanfaat.

Sumber: http://rndc.or.id/wi...a_PeriodikVersi

PHP Version:

PHP:
<?php
/*
Copyright (c) 2012 Augusta Bogie (@MasBog) (http://twitter.com/masbog)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

for periodic action, i use cronjob on my server... and

PLEASE READ TWITTER API LIMIT, if you want your twitter account is not suspended.
*/

//download twitter PHP library EpiCurl from https://github.com/masbog/twitter-async
include 'lib/EpiCurl.php';
include 'lib/EpiOAuth.php';
include 'lib/EpiTwitter.php';

$consumerKey = '';
$consumerSecret = '';
$oauthToken = '';
$oauthSecret = '';

$twitterObj = new EpiTwitter($consumerKey, $consumerSecret, $oauthToken, $oauthSecret);
$twitterObj->setToken($oauthToken, $oauthSecret);

//$req = $twitterObj->get_accountVerify_credentials();
//var_dump($req->response);

//echo "<BR>";

function base64_encode_image ($imagefile) {
$imgtype = array('jpg', 'gif', 'png');
$filename = file_exists($imagefile) ? htmlentities($imagefile) : die('Image file name does not exist');
$filetype = pathinfo($filename, PATHINFO_EXTENSION);
if (in_array($filetype, $imgtype)){
$imgbinary = fread(fopen($filename, "r"), filesize($filename));
} else {
die ('Invalid image type, jpg, gif, and png is only allowed');
}
return base64_encode($imgbinary);
}

function random_image()
{
$folder = opendir(dirname( __FILE__ ) . '/image-dir/');
$i = 0;
while(false !=($file = readdir($folder))){
if($file != "." && $file != ".."){
$images[$i]= $file;
$i++;
}
}
$random_img = rand(0,count($images)-1);
echo '<img src="image-dir/'.$images[$random_img].'" alt="" /><br>';

//$filename = dirname( __FILE__ ) . '/image-dir/' . mt_rand(3180,3219) . '.png';
//echo $filename.'<br>';
//$imageEncode = base64_encode_image($filename);
$imageEncode = base64_encode_image(dirname( __FILE__ ) . '/image-dir/'.$images[$random_img]);
echo dirname( __FILE__ ) . '/image-dir/'.$images[$random_img].'<br>';
return $imageEncode;
}

$imageEncoded = random_image();
echo $imageEncoded.'<br>';

$uploadImageAvatar = $twitterObj->post_accountUpdate_profile_image(array('image' => $imageEncoded));
var_dump($uploadImageAvatar->response);

?>
 
Top