2013-10-03 74 views
0

我想通過代碼在Twitter上關注用戶。我正在使用下面提到的代碼。如何在Twitter上關注用戶?

HttpWebRequest messageRequest = 
(HttpWebRequest)WebRequest.Create("http://twitter.com/friendships/create/" + 
              userIdToFollow + ".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(); 

而得到響應

The remote server returned an error: (404) Not Found.

我失去的東西,我得到一個錯誤?

回答

1

您使用的是什麼版本的API?

V1

https://dev.twitter.com/docs/api/1/post/friendships/create

V1.1

https://api.twitter.com/1.1/friendships/create.json


我不知道你在哪裏得到了該網址,但您是否嘗試過使用HTTPS

+0

你能給一些示例代碼。這將是非常有用的。感謝您的回覆 – SCV

+0

https://dev.twitter.com/docs/api/1.1/post/friendships/create – hunter

+0

迄今爲止的幫助hunter +1:感謝您的幫助。你能修改我的代碼來使它工作嗎? – SCV

1

是的。正確的網址:

https://api.twitter.com/1.1/friendships/create 

看到這個資源:https://dev.twitter.com/docs/api/1.1/post/friendships/create

+0

代碼行應該是這樣的:'HttpWebRequest messageRequest =(HttpWebRequest)WebRequest.Create(「https://api.twitter.com/1.1/friendships/create/」+ UserToFollow +「.xml?follow = true」) ;'? – SCV

+0

不,您傳遞用戶ID作爲查詢字符串參數。請閱讀文檔。它會回答你所有的問題。 –

+0

Chris +1:感謝您的幫助。你可以請幫助如何通過用戶名和C#中的參數作爲參數? – SCV

相關問題