@@timestamp = nil
def generate_oauth_url
@@timestamp = timestamp
url = CONNECT_URL + REQUEST_TOKEN_PATH + "&oauth_callback=#{OAUTH_CALLBACK}&oauth_consumer_key=#{OAUTH_CONSUMER_KEY}&oauth_nonce=#{NONCE} &oauth_signature_method=#{OAUTH_SIGNATURE_METHOD}&oauth_timestamp=#{@@timestamp}&oauth_version=#{OAUTH_VERSION}"
puts url
url
end
def sign(url)
Base64.encode64(HMAC::SHA1.digest((NONCE + url), OAUTH_CONSUMER_SECRET)).strip
end
def get_request_token
url = generate_oauth_url
signed_url = sign(url)
request = Net::HTTP.new((CONNECT_URL + REQUEST_TOKEN_PATH),80)
puts request.inspect
headers = { "Authorization" => "Authorization: OAuth oauth_nonce = #{NONCE}, oauth_callback = #{OAUTH_CALLBACK}, oauth_signature_meth od = #{OAUTH_SIGNATURE_METHOD}, oauth_timestamp=#{@@timestamp}, oauth_consumer_key = #{OAUTH_CONSUMER_KEY}, oauth_signature = #{signed_url}, oauth_versio n = #{OAUTH_VERSION}" }
request.post(url, nil,headers)
end
def timestamp
Time.now.to_i
end
我試圖做oauth嘗試瞭解如何使用授權標頭。我也收到以下錯誤。我正嘗試連接到linkedin API。net/http.rb:560:in`initialize':getaddrinfo:名稱或服務未知(SocketError)
/usr/lib/ruby/1.8/net/http.rb:560:in 'initialize': getaddrinfo: Name or service not known (SocketError)
我真的很感激,如果有人可以輕移我在正確的方向。
我從我的服務器當我嘗試使用Git與GitLab收到此錯誤。消息通過ssh在我的終端輸出。錯誤發生在Twp天前,現在它消失了。也許我的linode主機遇到DNS麻煩? – trusktr 2014-04-18 15:52:29
這工作,我把我的'wifi'和轉身'上'瞧它完成了 – illusionist 2016-09-06 18:22:13