Tweet gönderebilmek için Github'da yer alan OAuth.php ve twitteroauth.php dosyalarını indirip application/libraries klasörüne kopyalıyoruz. Daha sonra twitteroauth.php dosyasını fonksiyon içinde projemize dahil ediyoruz.
class Twitter extends CI_Controller {
private $consumerKey = 'Uygulama key';
private $consumerSecret = 'Uygulama secret';
private $oAuthToken = 'Uygulama token';
private $oAuthSecret = 'Uygulama secret';
public function sentTweet() {
$data = array();
$data["consumerKey"] = $this->consumerKey;
$data["consumerSecret"] = $this->consumerSecret;
$data["oAuthToken"] = $this->oAuthToken;
$data["oAuthSecret"] = $this->oAuthSecret;
$CI = & get_instance();
$CI->load->library('twitteroauth', $data);
$tweetText = "Bizimkini hiç denediniz mi? bizimki.com";
$status = array('status' => $tweetText);
$this->twitteroauth->post('statuses/update', $status);
}
}
Tweet atmak istediğimiz yazıyı ($tweetText) belirleyip post metodu ile gönderilmesini sağlıyoruz.