Skip to content

Instantly share code, notes, and snippets.

@gregimba
Created June 24, 2013 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregimba/5853266 to your computer and use it in GitHub Desktop.
Save gregimba/5853266 to your computer and use it in GitHub Desktop.
<form action="tweet.php" method="post">
<p>Your tweet: <input type="text" name="tweet" /></p>
<p>Your @(handle): <input type="text" name="handle" /></p>
<p><input type="submit" /></p>
</form>
<?php
require 'vendor/autoload.php';
$consumerKey = 'xxxxxxxxxxxxxxxxxxxxx';
$consumerSecret = 'xxxxxxxxxxxxxxxxxxxxx';
$accessToken = 'xxxxxxxxxxxxxxxxxxxxx';
$accessTokenSecret = 'xxxxxxxxxxxxxxxxxxxxx';
$twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
try {
$tweet = $twitter->send($_POST['tweet'].' by '.$_POST['handle'] );
} catch (TwitterException $e) {
echo 'Error: ' . $e->getMessage();
}
@nathancarnes
Copy link

Assuming your Twitter library returns false on a the send method in the event of a failure (which I'd hope it does), you could avoid try/catch by doing something like:

$tweet = $_POST['tweet'].' by '.$_POST['handle'];

if(!$twitter->send($tweet){
  // error handling
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment