RSS Feed

Showing Tweets in Your Own Website

Posted on

Sebelumnya, ga perlu pake oAuth buat ngambil json Tweets di twitter. Dengan API 1.1, semua harus melalui otorisasi untuk mengakses webservice Twitter. Langsung aja, gimana caranya nampilin tweets di website sendiri?

Bikin Twitter App

Creating Twitter App

Creating Twitter App

  1. Bikin apps dulu dengan pergi ke mari https://dev.twitter.com/apps/new, kalau belum login, ya login dulu pake akun Twitter Anda!
  2. Masupin datanya lalu klik Submit. Anda bakalan dapetin Consumer key dan Consumer secret.
  3. Nah di halaman ini, klik tombol Create my access token buat dapetin Access token dan Access token secret.
  4. Twitter App sudah sukses terbikin

Selanjutnya ialah tarik data tweets ini ke website pake PHP.

Tarik Data Tweets pake PHP

Caranya, garpuh programnya di mari: http://github.com/abraham/twitteroauth. Ambil yang di folder twitterouth aja. Lalu di script PHP Anda, masupin ini:

...
//get the tweets data in json format
require_once("../model/twitteroauth/twitteroauth.php");
$api_url = "http://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=aa_farid&count=10&trim_user=t";
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$data_twitter = $connection->get($api_url);

//show the tweets
foreach ($data_twitter as $dt_twitter){
    echo "Date: " . $dt_twitter->created_at;
    echo "Tweet: " . $dt_twitter->text;
}
...

CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET didapat dari Twitter App yang Anda bikin tadi loh. Timeout default request data adalah 30 detik

Demikian! Semoga berganu, karena berguna sudah mainstream!

Bahan Bacaan:
https://dev.twitter.com/discussions/11564
https://github.com/abraham/twitteroauth
https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

About mangkum

Models maker and fans: building view-controller-models, financial models, statistical models and a fan of super models.

One response »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: