Tags: Blog |
Categories: Blog
Posted by
admin on
3/9/2009 5:58 PM |
Comments (2)
Ok many developer problems can be avoid by reading all the documentation, yet, I normally try to jump into writing code as soon as I can, and figure it out by myself. This method got me in a lot of trouble and made me waste my time as well.
Twitter is really peculiar on how wants the post to follow and leave people. After playing for a while I was successful so I would like to share with you how to do that as the twitter API documentation does not explain it. Yet won’t be difficult for you to figure it reading all the documentation page.
Friendship Methods
create
Befriends the user specified in the ID parameter as the authenticating user. Returns the befriended user in the requested format when successful. Returns a string describing the failure condition when unsuccessful.
URL: http://twitter.com/friendships/create/id.format
Formats: xml, json
Method(s): POST
Parameters:
- id. Required. The ID or screen name of the user to befriend. Ex: http://twitter.com/friendships/create/12345.json or http://twitter.com/friendships/create/bob.xml
- follow. Optional. Enable notifications for the target user in addition to becoming friends. Ex: http://twitter.com/friendships/create/bob.json?follow=true
Make sure you read the authentication section as well to find out how to send your credentials and then how to create the request. Setting up the request took me longer than expected, I needed to set the all this in order to work, otherwise will return a 417 error.
request.Method = "POST"; request.ContentType = "application/xml"; request.AllowWriteStreamBuffering = true; request.UserAgent = "GeoTwitter"; request.Headers.Add("Authorization", "Basic " + Credentials); request.ServicePoint.Expect100Continue = false;
To create the credentials is pretty simple:
Convert.ToBase64String(Encoding.ASCII.GetBytes(UserName + ":" + Password));
That will return a string with your username and password in base64 to added into the header.
The data for the post is empty. Happy Twitting.
Cheers
Al
Follow me in twitter | bookmark me | Subscribe to my feed | Check out GeoTwitter | Create GeoRss content
Posted from
http://weblogs.asp.net/albertpascual
d5a4b1f8-2c89-4cc2-b499-a47c3ad15c5d|0|.0