public void PostTweet(string username, string password, string tweet)
{
try
{
// kullanıcı adı ve şifre encode ediliyor
string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("status=" + tweet);
// güncelleme sayfasına bağlanılıyor
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("
http://twitter.com/statuses/update.xml" ;);
// metod post olarak ayarlanıyor.
request.Method = "POST";
request.ServicePoint.Expect100Continue = false; // thanks to argodev for this recent change!
request.Headers.Add("Authorization", "Basic " + user);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bytes.Length;
Stream reqStream = request.GetRequestStream();
// yazılıyor
reqStream.Write(bytes, 0, bytes.Length);
// kapatılıyor
reqStream.Close();
}
catch (Exception ex) {/* burası boş */}
}
public enum FriendshipID
{
ByID,
ByUserID,
ByScreenName,
Follow
}
public string Friendship_Create(string username, string password, FriendshipID friendshipID, string id)
{
try
{
string responseStr = string.Empty;
switch (friendshipID)
{
case FriendshipID.ByID:
{
HttpWebRequest messageRequest = (HttpWebRequest)WebRequest.Create("
http://twitter.com/friendships/create/" ; + id + ".xml");
messageRequest.Method = "POST";
messageRequest.Credentials = new NetworkCredential(username, password);
messageRequest.ContentLength = 0;
messageRequest.ContentType = "application/x-www-form-urlencoded";
WebResponse response = messageRequest.GetResponse();
StreamReader sReader = new StreamReader(response.GetResponseStream());
responseStr = sReader.ReadToEnd();
break;
}
case FriendshipID.ByScreenName:
{
HttpWebRequest messageRequest = (HttpWebRequest)WebRequest.Create("
http://twitter.com/friend...ate.xml?screen_name=" ; + id);
messageRequest.Method = "POST";
messageRequest.Credentials = new NetworkCredential(username, password);
messageRequest.ContentLength = 0;
messageRequest.ContentType = "application/x-www-form-urlencoded";
WebResponse response = messageRequest.GetResponse();
StreamReader sReader = new StreamReader(response.GetResponseStream());
responseStr = sReader.ReadToEnd();
break;
}
case FriendshipID.ByUserID:
{
HttpWebRequest messageRequest = (HttpWebRequest)WebRequest.Create("
http://twitter.com/friend.../create.xml?user_id=" ; + id);
messageRequest.Method = "POST";
messageRequest.Credentials = new NetworkCredential(username, password);
messageRequest.ContentLength = 0;
messageRequest.ContentType = "application/x-www-form-urlencoded";
WebResponse response = messageRequest.GetResponse();
StreamReader sReader = new StreamReader(response.GetResponseStream());
responseStr = sReader.ReadToEnd();
break;
}
case FriendshipID.Follow:
{
HttpWebRequest messageRequest = (HttpWebRequest)WebRequest.Create("
http://twitter.com/friendships/create/" ; + id + ".xml?follow=true");
messageRequest.Method = "POST";
messageRequest.Credentials = new NetworkCredential(username, password);
messageRequest.ContentLength = 0;
messageRequest.ContentType = "application/x-www-form-urlencoded";
WebResponse response = messageRequest.GetResponse();
StreamReader sReader = new StreamReader(response.GetResponseStream());
responseStr = sReader.ReadToEnd();
break;
}
}
return responseStr;
}
catch (Exception ex)
{
return ex.Message;
}
}
//twitterCs.cs classımız
//textBox1.Text kullanıcı adı
//textBox2.Text şifre
//twitterCs.FriendshipID.ByScreenName burada ise ekranda görünen adı ile çağırıcağımızı belirtiyoruz
//textBox3.text burada ise arkadaş olarak eklenicek kişinin adı
t.Friendship_Create(textBox1.Text, textBox2.Text, twitterCs.FriendshipID.ByScreenName, textBox3.text);