Tweet via PHP

Hi there. I’ve been tinkering with PHP and the Twitter API and I’ve had some level of success.

Assuming I have registered an app with twitter and have my access keys and tokens. Can someone help me with two things that have me stumped:

  1. RETWEET a specific tweet via PHP.
  2. Use a single set of keys/tokens to post tweets for multiple users.


  1. PHP Class:

  2. PHP Function

[php]function tweet($status, $consumer_key, $consumer_secret, $user_token, $user_secret){
$tmhOAuth = new tmhOAuth(array(
‘consumer_key’=> $consumer_key,
‘consumer_secret’ => $consumer_secret,
‘user_token’ => $user_token,
‘user_secret’ => $user_secret,
$tmhOAuth->request(‘POST’, $tmhOAuth->url(‘1/statuses/update’), array(
‘status’ => $status
3. (register an app, get keys foreach account)

  1. tweet(“yay!”, …);

  2. goto 4 but with different keys

I appreciate the help.

What you’re written will tweet, which I can already do. As I said in the original post, I’d like the syntax for retweeting and am wondering how to use a single set of keys for multiple users.

Figured it out part 1 (retweeting)



// Include twitteroauth

// Set keys

// Create object
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);

// Set tweet ID to be retweeted

$postID = 3821XXXXXXX1313;

// Post the retweet

$tweet->post(‘statuses/retweet’, array(‘id’ => $postId));


Sponsor our Newsletter | Privacy Policy | Terms of Service