Raised This Month: $51 Target: $400
 12% 

[TUT] How to post on Twitter from CS


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 02-04-2010 , 09:00   [TUT] How to post on Twitter from CS
Reply With Quote #1

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:
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:
@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

PHP Code:
public plugin_cfg()
{
    
register_clcmd("say""say_handler")
}

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

    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:
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.
Attached Files
File Type: sma Get Plugin or Get Source (tweet.sma - 1155 views - 4.4 KB)
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
01101101
BANNED
Join Date: Nov 2009
Location: 9`su 09`n0n7e`r0f76a
Old 02-04-2010 , 09:04   Re: [TUT] How to post on Twitter from CS
Reply With Quote #2

n1 i never took much interest in sockets but they seem really useful

Edit:

Why are you messing so much with this?

PHP Code:
        formatex(requestcharsmax(request), "POST %s%s HTTP/1.1^n"g_urltmp)
        
formatex(request2charsmax(request2), "%sHost: %s^nAccept-Encoding: none^n"requestg_host)
        
formatex(requestcharsmax(request), "%sAuthorization: Basic %s^n"request2encoded)
        
formatex(request2charsmax(request2), "%sConnection: Close^n^n"request)
        
socket_send(socketrequest2charsmax(request2)) 
If you could use a single formatex?
Or, 2 formats could also be posible, since you can rewrite them.

Last edited by 01101101; 02-04-2010 at 09:07.
01101101 is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 02-04-2010 , 09:10   Re: [TUT] How to post on Twitter from CS
Reply With Quote #3

Quote:
Originally Posted by 01101101 View Post

Why are you messing so much with this?

PHP Code:
        formatex(requestcharsmax(request), "POST %s%s HTTP/1.1^n"g_urltmp)
        
formatex(request2charsmax(request2), "%sHost: %s^nAccept-Encoding: none^n"requestg_host)
        
formatex(requestcharsmax(request), "%sAuthorization: Basic %s^n"request2encoded)
        
formatex(request2charsmax(request2), "%sConnection: Close^n^n"request)
        
socket_send(socketrequest2charsmax(request2)) 
If you could use a single formatex?
Or, 2 formats could also be posible, since you can rewrite them.
Because I'm crazy and I like clean code.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 02-04-2010 , 15:10   Re: [TUT] How to post on Twitter from CS
Reply With Quote #4

I was working with Facebook ( http://forums.alliedmods.net/showthread.php?t=117776 ). And you have to create a sessionid.

Also facebook is very secury. But any won me!!!
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
rak
Veteran Member
Join Date: Oct 2011
Location: banned country
Old 03-22-2012 , 01:47   Re: [TUT] How to post on Twitter from CS
Reply With Quote #5

this don't work I put first in the list of plugin.ini.. but show me the admin message..
__________________

www.amxmodx-es.com

Steam: Luchokoldo

Last edited by rak; 03-22-2012 at 01:48.
rak is offline
Send a message via MSN to rak Send a message via Skype™ to rak
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-22-2012 , 02:09   Re: [TUT] How to post on Twitter from CS
Reply With Quote #6

Quote:
Originally Posted by rak View Post
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.
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:28.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode