2010-04-09 14 views
9
@@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 

che sto cercando di fare quello che OAuth fa, nel tentativo di capire come utilizzare le intestazioni di autorizzazione. Sto anche ricevendo il seguente errore. Sto cercando di connettermi all'API linkedin.net/http.rb: 560: in `inizializzare ': getaddrinfo: Nome o servizio non nota (Errore socket)

/usr/lib/ruby/1.8/net/http.rb:560:in 'initialize': getaddrinfo: Name or service not known (SocketError)

Vorrei davvero apprezzare se qualcuno mi potrebbe spingere nella giusta direzione.

risposta

18

"Nome o servizio non nota" è un errore a livello di presa che di solito indica sia un nome host/indirizzo DNS IP non valido, o un nome di porta non registrato (ad es telnet the.host.name service dove service non è un nome registrato.)

Verificare che CONNECT_URL abbia un URL valido.

EDIT: Io non sono un programmatore Ruby, ma non mi dispiacerebbe scommettendo che Net::HTTP.new richiede un nome host (ad esempio www.facebook.com) come primo argomento, non un URL completo (ad esempio www.facebook .com/login.php? method = OAuth).

9

Si ottiene questo errore anche quando non si dispone di una connessione Internet poiché una ricerca DNS è spesso la prima cosa che accade quando si stabilisce una connessione TCP utilizzando un nome host.

Scollegare il cavo di rete e provare:

Socket.getaddrinfo("www.example.com", "http") 
# => SocketError: getaddrinfo: nodename nor servname provided, or not known 
+0

che sto ricevendo questo errore dal mio assistente quando provo usando git con GitLab. Il messaggio viene emesso nel mio terminale tramite ssh. L'errore era lì Twp giorni fa, e ora non c'è più. Forse il mio host linode stava riscontrando problemi DNS? – trusktr

+0

Questo ha funzionato, ho attivato il mio 'wifi' e ho attivato' on' e voilà – illusionist

Problemi correlati