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.

thanks!

  1. PHP Class: https://github.com/themattharris/tmhOAuth

  2. PHP Function

[php]function tweet($status, $consumer_key, $consumer_secret, $user_token, $user_secret){
include(“class.twitter.php”);
$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
));
}[/php]
3. https://dev.twitter.com/apps/new (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)

[php]<?php

date_default_timezone_set(‘America/New_York’);

// Include twitteroauth
require_once(‘twitteroauth.php’);

// Set keys
$consumerKey = ‘XXXXXXXXXXXXXXXXXXXXXX’;
$consumerSecret = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’;
$accessToken = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’;
$accessTokenSecret = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’;

// 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));

?>
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service