PHP

Auto Post to Twitter

Well after I solved my task of auto posting to Facebook, I got assigned with doing the same thing but for Twitter. Luckily, this is so much easier than posting to Facebook.

Register Your Twitter Application

Start by creating an application with Twitter. You can fill out the info however you like. None of it will matter for automatically posting tweets.

Download the Twitter OAuth API Library

Twitter has a bunch of different API libraries but I used TwitterOAuth by Abraham Williams. Download it here.

Create the Auto Tweeter

Now lets create the auto poster/tweeter. It’s really easy. I couldn’t believe how painless this was.

// Twitter Class
require_once('path/to/twitteroauth/twitteroauth.php');
 
// Twitter Connection Info
$twitter_access_token = 'xxx';
$twitter_access_token_secret = 'xxx';
$twitter_consumer_key = 'xxx';
$twitter_consumer_secret = 'xxx';
         
// Connect to Twitter
$connection = new TwitterOAuth($twitter_consumer_key, $twitter_consumer_secret, $twitter_access_token, $twitter_access_token_secret);
         
// Post Update
$content = $connection->post('statuses/update', array('status' => 'Test Tweet'));


The consumer key and secret are under your Twitter application details and the access token and secret are under Application details -> My Access Token. Plug those in above and you’re good to go.
Теги:
Twitter, no translate
Добавлено: 17 Июня 2015 07:54:45 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...