如何在Twitter上发布消息 [英] How to Post a message on Twitter

查看:517
本文介绍了如何在Twitter上发布消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI
我收到错误消息"远程服务器返回错误:(401)未经授权."

我在很多站点都看到过,但都没有解决问题.

我试图在2天之内解决此问题,但我无法解决.请帮我提供一些示例代码.

这是现在正在使用的代码,

HI
I am getting an error "The remote server returned an error: (401) Unauthorized."

i have seen in so many sites but none of them solved the problem.

I am trying to fix this problem past 2 days but iam not able to do so. Please help me with some sample codes.

This is the code am using now,

Sub TwitIt(ByVal strUser As String, ByVal strPass As String, ByVal strMessage As String)
        'this subroutine requires your ASP.NET page to have a label control with an ID of lblStatus
        'create post variable for tweet
        Dim strTweet As String = "status=" & Server.HtmlEncode(strMessage)
        'convert post variable to byte array for transmission purposes
        Dim bRequest As Byte() = System.Text.Encoding.ASCII.GetBytes(strTweet)
        Try
            'create HttpWebRequest to status update API resource
            Dim objRequest As HttpWebRequest = WebRequest.Create("http://twitter.com/statuses/update.xml")
            'pass basic authentication credentials
            objRequest.Credentials = New NetworkCredential(strUser, strPass)
            'set method to post and pass request as a form
            objRequest.Method = "POST"
            objRequest.ContentType = "application/x-www-form-urlencoded"
            'tell the server it will not receive a 100 Continue HTTP response
            objRequest.ServicePoint.Expect100Continue = False
            'set content length of request
            objRequest.ContentLength = bRequest.Length
            'capture the stream (content) of the request
            Dim objStream As Stream = objRequest.GetRequestStream()
            'put the bytes into request
            objStream.Write(bRequest, 0, bRequest.Length)
            'close the stream to complete the request
            objStream.Close()
            'uncomment line below to report success
            'lblStatus.Text = "Tweet sent!"
            'You can also capture the XML response Twitter sends back
            'uncomment lines below to capture responses
          Dim objResponse As WebResponse = objRequest.GetResponse()
            Dim objReader As New StreamReader(objResponse.GetResponseStream())
            lblStatus.Text = objReader.ReadToEnd()
        Catch ex As Exception
            'uncomment line below to report ASP.NET errors
            lblStatus.Text = ex.Message
        End Try
    End Sub




这是导致该问题的行"昏暗的objResponse As WebResponse = objRequest.GetResponse()
"


任何帮助都是可观的

谢谢
Govind




This is the line which causes that problem " Dim objResponse As WebResponse = objRequest.GetResponse()
"


Any Help would be appreciable

Thanks
Govind

推荐答案

错误消息不是自描述的吗?您只需要在同一会话中进行授权即可.转到授权页面,然后使用查看页面源代码"查看所需的授权参数,协议(可以是HTTPS而不是HTTP)和HttpWebRequest方法(也应该是"POST").创建HttpWebRequest的实例,并使用它以与您已经使用的相同方式发布授权数据.获得授权后,尝试以已有的方式向您发布消息.

(以防万一:希望您能理解,如果您使用Web浏览器通过了授权,那么它就无济于事.会话是按浏览器进行标识的.您的应用程序从一开始就应该扮演浏览器的角色.)

—SA
Isn''t the error message self-describing? You simply need to authorize in the same session. Go to the authorization page and use "View page source" to see what parameters of authorizations are expected, what''s the protocol (could be HTTPS instead of HTTP) and HttpWebRequest method (should also be "POST"). Create an instance of HttpWebRequest and use it to post authorization data the same way you already use. When you are authorized, try to post you message the way you already do.

(Just in case: hope you understand, that if you passed authorization using a Web browser, it cannot help. The sessions are identified on the per-browser basis. Your application should play the role of browser from the very beginning.)

—SA


这篇关于如何在Twitter上发布消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆