dimanche 28 février 2016

Posting random-ish tweet with php and codebird

Ok I'm using php and codebird to generate tweets once an entry has been added to my database and here is the sample of whats working well.

 $params = array(
    'status' => "Some text " . $name[0] ." some text " . $body
 );
 $reply = $cb->statuses_update($params);

This works with ever database entry with no issues.

So now I want to create a few different standard messages and pick one at random. I've been able to partially achieve this with array_rand() with the following:

$tweets = array(
    "Some text " . $name[0] ." Some text " . $body,
    "Different text " . $name[0] ." different text " . $body,
    "text " . $name[0] ." text " . $body,
    "new text ". $name[0] ." new text " . $body
);

$key = array_rand($tweets, 1);
$params = array(
    'status' => $tweets[$key]
);

This seems to be working most the time but it seems that 15% of the time a database entry that should trigger a new tweet doesn't. I've seen every one of my tweet options published as a tweet so it would seem its a random problem with using array_rand(). Thanks in advance




Aucun commentaire:

Enregistrer un commentaire