bcmcfc
bcmcfc

Reputation: 26825

How to send a tweet from PHP with OAuth?

There's a few tutorials and classes out there but they no longer appear to work since Twitter changed to oAuth.

How do I send a tweet from PHP, in the most basic way possible?

For example, the 'old' way using the MyTwitter class was as follows:

require_once('MyTwitter.class.php');
$twitter =  new MyTwitter('username', 'password');
$message = "API Test.";
$result = $twitter->updateStatus($message);
print_r($result);

Upvotes: 2

Views: 3664

Answers (2)

bcmcfc
bcmcfc

Reputation: 26825

The demo didn't work, but the class itself did-

    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
    $content = $connection->get('account/verify_credentials');
    $result = $connection->post('statuses/update', array('status' => $message));

Upvotes: 4

robjmills
robjmills

Reputation: 18598

Theres a good walkthrough here of implementing Twitter OAuth, complete with a working demo. If you're already using a framework you probably have other options also such as Zend_Service_Twitter in Zend Framework

Upvotes: 2

Related Questions