且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Twitter oauth golang 收到错误“代码":32,“消息":“无法对您进行身份验证".

更新时间:2022-12-07 22:46:11

能够解决问题.我做了两个更改:

Able to solve the problem. I made two changes:

  1. 在传递用于加密以创建签名之前对 params 变量进行编码

  1. encoded the params variables before passing for encryption to create signature

baseString := "POST"+"&"+ encode(twitterConf.Endpoint.RequestTokenUrl) + "&"+encode(params.Encode())

baseString := "POST"+"&"+ encode(twitterConf.Endpoint.RequestTokenUrl) + "&"+encode(params.Encode())

为了创建标题,我创建了自己的标题字符串

To create header, I created my own header string

    headerstring := "OAuth oauth_callback=\"http%3A%2F%2Flocalhost%3A8080%2Foauth%2FtwitterOauth2callback\",oauth_consumer_key=\"consumerkey\",oauth_nonce=\"" +
        params.Get(NONCE_PARAM) + "\",oauth_signature=\"" + escape(signature) + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" + params.Get(TIMESTAMP_PARAM) +
        "\",oauth_token=\"" + escape("oauth token") + "\",oauth_version=\"1.0\""

reqnew.Header.Add("Authorization", headerstring)

reqnew.Header.Add("Authorization", headerstring)

这解决了问题,我开始获取访问令牌

This solved the problem and I started getting access token