Main Menu

Login Form

Syndication

If you try to search in the Web info about creating Twitter bot then you will find a lot if articles and blog messages about this. But most of them are just examples of code that posts twitt (message) to Twitter.

This is not enough to create full function Twitter bot.

Good Twitter bot should: post twitts, subscribe for new users by given subject, somehow make another users to subscribe for needed account. Actually, last task is most important - grow count of subscribers for some account.

There is example of such bot - Extended Twitter bot with PHP.

I used twitterlibphp to work with Twitter API. It is nice PHP class by Justin Poliey.

I think most useful task of Twitter bot is to increase count of subscribers for some twitter account.

To achieve this i used my own resume after using of twitter. Usually, when some account becomes my subscriber i get notification email and i am going to look what is that account. If that is something i am interested in i subscribe for that account too.

Based on this resume, i created bot that have list of functions:

Search for tweets by some keywords and add found twitter account to DB table

Get accounts from DB table that i am not subscribed and never was subscribed.

Filter accounts with special condition

Subscribe for selected accounts

Update my twitter status with messages from DB (that is what any twitter bot does )

Get list of my subscribers and accounts that i am subscribed on.

Select and remove accounts that i subscribed but they didn't subscribed me after some time (it is not good to be subscribed for too many accounts, so remove "bad" accounts).

Filtering of accounts to subscribe

It is easy to search for accounts by keywords. But not all accounts are good for subscription . There are a lot of bots in the Twitter. I read somewhere that 80% of accounts are bots!

It is needed to filter bots accounts and process only "real" accounts - accounts that are used by human .

To solve this task i also used my experience in twitter. I found that real accounts have few subscriptions (<50) and bots usually have a lot of subscriptions (>100) .

So, there is simple criteria. If account have more then 50 subscriptions then this is bot and account must be ignored. This is not 100% true. But i most cases this works.

Functioning of the bot.

Another important thing for twitter bot (and any other bot) is balance in doing of API requests. It is not good to do request by request. In this case twitter can easy know that this are requests from a bot.

My bot works with scenario that is saved in settings.

Scenario looks like:

search,pause,message,pause,subscribe:5,pause,message

Cron task starts the bot each minute. The bot looks in DB for next step in scenario and execute task. Pause means to do nothing.

Yes. I want to publish it. But that bot will need to be modified. Because twitter removed Basic authentication from API. Now user can be authentificated only with oAuth. I think i will publish that code at next week.