Write a tweet using “twitterOAuth” return an error

2019-03-04 11:34发布

问题:

I have this problem and are a lot of days that i'm tring to solve it.

I write a tweet using twitterOAuth

// OAuth To Twitter
require_once 'files-notifiche-twitter/twitteroauth.php';

// Do NOT Share (sono i token)
define("CONSUMER_KEY", "xxx");
define("CONSUMER_SECRET", "xxx");
define("OAUTH_TOKEN", "xxx");
define("OAUTH_SECRET", "xxx");

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


if ($connection->getLastHttpCode() != 200) {    //se non è riuscito a scrivere il tweet riprova
    print_r('<br>Error try again<br>');     
} 
else{
    print_r('<br>Notifica twitter funziona<br>');
}

print_r('OK');

This code works to write the tweet but then, in the last part, is how ther's an error...infact the print_r inside if statement is didn't write. The same for last print_r('OK')

Something break my code and i don't understand what....

Can you help me?