1

I want to make a function that will send automatic tweet when ever I publish some post on WordPress website. So I have included Codebird library inside functions.php, but I have problem with creating a function for tweeting. The tweeting function doesn't work.

function post_to_twitter($message)
{
    $consumer_key = '....';
    $consumer_secret = '....';
    $access_token = '....';
    $access_secret = '....';

    \Codebird\Codebird::setConsumerKey($consumer_key, $consumer_secret);
    $cb = \Codebird\Codebird::getInstance();
    $cb->setToken($access_token, $access_secret);

    $params = array(
      'status' => $message
    );
    $reply = $cb->statuses_update($params);
}

$message = 'New post published';
post_to_twitter($message);

When I put it outside the function, it works, like this

$consumer_key = '....';
$consumer_secret = '....';
$access_token = '....';
$access_secret = '....';
$message = 'New post published';

\Codebird\Codebird::setConsumerKey($consumer_key, $consumer_secret);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken($access_token, $access_secret);

$params = array(
  'status' => $message
);
$reply = $cb->statuses_update($params);
Michael Shopsin
  • 2,055
  • 2
  • 24
  • 43
Petar Popovic
  • 575
  • 6
  • 20

0 Answers0