[TUT] How to post on Twitter from CS (not working anymore)

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1367
Gender:
United States of America

[TUT] How to post on Twitter from CS (not working anymore)

Post by Archive-Poster »

WARNING: NO LONGER WORKS

First of all, this tutorial is intended to show an example of how to use some web-services APIs so you should have knowledge about sockets and http protocol.

In this case I'm using Twitter web API that allows you to update your status with a single request.

Because of this example will run over only one account of Twitter, that account should be, for example, for your CS community.

Requirements:
You must have sockets module loaded and allowed in your host provider
You must have a Twitter account
You have to know the username and password of that account

Step 1: Twitter API
Twitter API allows people to make their own software that interacts within Twitter.

As for update status task, you only need to send your new text using this url and this parameter:

Code: Select all

http://twitter.com/statuses/update.xml?status=Your new status text
Step 2: How can we allow players to send tweets!?
You can handle say command to manage only those messages that starts with a tag. I'm using the tag @tw.

So, if player says

Code: Select all

@tw Hello World!
That text will be posted as a tweet... of course on Twitter.

I guess everybody knows how to handle say but here's an example

Code: Select all

public plugin_cfg()
{
    register_clcmd("say", "say_handler")
}

public say_handler(id)
{
    static message[64]
    read_args(message, 63)

    if(!(message[0] == '@') || !(message[1] == 't') || !(message[2] == 'w') || !(message[3] == ' '))
        return PLUGIN_CONTINUE

    server_print("Player ID %i tries to tweet: ^"%s^"", message[4])
    return PLUGIN_HANDLED
} 
Step 3: Let's go!
This are the tasks we have to do to make a single HTTP request that tweets
Encode using base64 your username and password (see stock)
Make sure the text that will be sent over HTTP request are encoded (see stock)
Open a socket to twitter.com web server and send the request like the following example

Code: Select all

POST /statuses/update.xml?status=Hello+World!
Host: twitter.com
Authorization: Basic dXNlcjpwYXNz
Connection: close
Look that the string and credentials are encoded (with different techniques).

Step 4: Example plugin
I will share a small plugin that let's you send tweets when you're playing.
It has a few cvars to setup credentials and permissions (admin only or all users)

Notes
This technique it's valid for a lot of applications (Twitter, Facebook, LinkedIn). Also you can make your own web application to manage such kind of messages and the use it as your needs.

For example you could write a web application that receives alerts from server (hacks detected, users compliants, etc) and then forward to MSN, TALK, YAHOO, AIM, etc. Also you can store to have the history of every message received.
Attachments
tweet.sma.zip
(1.84 KiB) Downloaded 8 times
User avatar
Archive-Poster
Posts: 1367
Gender:
United States of America

Re: [TUT] How to post on Twitter from CS

Post by Archive-Poster »

this don't work I put first in the list of plugin.ini.. but show me the admin message..
Twitter has since changed their authentication method (now OAuth) so this will no longer work.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest