Reputation: 61
I installed twitteroauth via composer.
I am trying to get a PHP script running that posts a test tweet. I have setup a developer account on Twitter as per instructions on the web and have been granted "Elevated" developer access but my script won't work. I get an error with no description.
Any help would be much appreciated. Thanks
Code is:
<?php
require_once "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', 'xx');
define('CONSUMER_SECRET', 'xx');
define('ACCESS_TOKEN', 'xx');
define('ACCESS_TOKEN_SECRET', 'xx');
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$status = 'This is a test tweet.';
$result = $connection->post("statuses/update", ["status" => $status]);
if ($connection->getLastHttpCode() == 200) {
echo "Your Tweet posted successfully.";
} else {
echo 'error: ' . $result->errors[0]->message;
}
?>
Upvotes: 1
Views: 360
Reputation: 61
I got it working. I had to enable Read and Write permissions in the Developer settings for the relevant project.
Upvotes: 2