Twitter: simple favorite’ing bot on PHP

Recently I found out that lot of twitter bots are favorite’ing and retweetting you statuses. I decided to create my own to play around a little.

Simple search for PHP library, showed me that there are many of these here Twitter Libraries.

I selected J7mbo/twitter-api-php and played around a little.

Here is what I got:

ini_set('display_errors', 1);

/** Set access tokens here - see: **/
$settings = array(
    'oauth_access_token' => "ACCESS_TOKEN",
    'oauth_access_token_secret' => "ACCESS_TOKEN_SECRET",
    'consumer_key' => "API_KEY",
    'consumer_secret' => "API_KEY_SECRET"

$url = '';
$getfield = '?q=#kosher+AND+#healthy';
$requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
    ->buildOauth($url, $requestMethod)

$result = json_decode($response);
foreach ($result->statuses as $ind=>$val)
    $postfields = array("id"=>$val->id);
    $requestMethod = 'POST';

    $twitter = new TwitterAPIExchange($settings);
    $response =  $twitter->buildOauth($url, $requestMethod)



This bot just searches for twits with hashtags #kosher and #healthy and favorites them. As a result, returns the twit you just favorited.

Leave a Reply

%d bloggers like this: