Ruby on rails RoR Twitter API oAuth:“;无法验证您的身份。”;

Ruby on rails RoR Twitter API oAuth:“;无法验证您的身份。”;,ruby-on-rails,api,twitter,omniauth,omniauth-twitter,Ruby On Rails,Api,Twitter,Omniauth,Omniauth Twitter,我尝试将我的应用程序连接到Twitter API。 我不确定,但我认为我的问题来自oauth_签名。 因此,我阅读了以下文档: 我想我做了他们说的每件事,但这不起作用,我也不知道为什么 这是我的密码: def build_url_api(参数、令牌、帐户、秘密令牌) 消费者密钥='xxx' 机密用户密钥='xxx' oauth_consumer_key=consumer_key oauth_签名_方法=“HMAC-SHA1” oauth_timestamp=Time.zone.now.to_i

我尝试将我的应用程序连接到Twitter API。 我不确定,但我认为我的问题来自oauth_签名。 因此,我阅读了以下文档:

我想我做了他们说的每件事,但这不起作用,我也不知道为什么

这是我的密码:

def build_url_api(参数、令牌、帐户、秘密令牌)
消费者密钥='xxx'
机密用户密钥='xxx'
oauth_consumer_key=consumer_key
oauth_签名_方法=“HMAC-SHA1”
oauth_timestamp=Time.zone.now.to_i.to_s
oauth\u nonce=Digest::SHA256.hexdigest(oauth\u时间戳)[0..16]
oauth_version=“1.0”
oauth_令牌=令牌
url='1〕https://api.twitter.com/1.1/statuses/user_timeline.json'
参数='oauth\u consumer\u key='+
oauth_消费者_密钥+
“&oauth\u nonce=”+
现在+
“&oauth\u签名\u方法”+
oauth_签名法+
“&oauth_timestamp=”+
oauth_时间戳+
“&oauth_令牌=”+
oauth_代币+
“&oauth_version=”+
oauth_版本
base_string='GET&'+CGI.escape(url)+'&'+CGI.escape(参数)
secret_key=secret_consumer_key+'&'+secret_令牌
oauth_signature=CGI.escape(Base64.encode64(“#{OpenSSL::HMAC.digest('sha1',secret_key,base_string)}”).chomp)
url=url+'?'+parameters+'&oauth_签名='+oauth_签名

结束
真丢脸我找到了解决方案:

我刚刚有一把旧的消费钥匙

我这里的代码示例运行良好