Ruby/httparty: cronometraggio quando si aggiunge feed a Google Reader usando la sua API
-
30-10-2019 - |
Domanda
Sto tentando di aggiungere un abbonamento a Google Reader, usando la sua API, tuttavia ricevo il seguente errore:
L'esecuzione è scaduta
Non ho avuto problemi a leggere (usando "get") un elenco di abbonamenti o tag. Ma si scatena quando provo ad aggiungere un sub (usando "post")
Il codice è scritto in Ruby on Rails e sto usando Httparty per gestire la comunicazione con il servizio Web.
Il mio codice è il seguente (sono ancora nuovo a Ruby/Rails, quindi mi dispiace per eventuali cattive pratiche incluse di seguito. Sono più che felice di averli indicati):
class ReaderUser
# Include HTTParty - this handles all the GET and POST requests.
include HTTParty
...
def add_feed(feed_url)
# Prepare the query
url = "http://www.google.com/reader/api/0/subscription/quickadd?client=scroll"
query = { :quickadd => feed_url, :ac => 'subscribe', :T => @token }
query_as_string = "quickadd=#{CGI::escape(feed_url)}&ac=subscribe&T=#{CGI::escape(@token.to_s)}"
headers = { "Content-type" => "application/x-www-form-urlencoded; charset=UTF-8", "Content-Length" => query_as_string.length.to_s, "Authorization" => "GoogleLogin auth=#{@auth}" }
# Execute the query
self.class.post(url, :query => query, :headers => headers)
end
...
end
Per riferimento, è così che sto ottenendo il token:
# Obtains a token from reader
# This is required to 'post' items
def get_token
# Populate @auth
get_auth
# Prepare the query
url = 'http://www.google.com/reader/api/0/token'
headers = {"Content-type" => "application/x-www-form-urlencoded", "Authorization" => "GoogleLogin auth=#{@auth}" }
# Execute the query
@token = self.class.get(url, :headers => headers)
end
# Obtains the auth value.
# This is required to obtain the token and for other queries.
def get_auth
# Prepare the query
url = 'https://www.google.com/accounts/ClientLogin'
query = { :service => 'reader', :Email => @username, :Passwd => @password }
# Execute the query
data = self.class.get(url, :query => query)
# Find the string positions of AUTH
auth_index = data.index("Auth=") + 5
# Now extract the values of the auth
@auth = data[auth_index,data.length]
end
Sarei felice di fornire ulteriori informazioni richieste.
Grazie in anticipo!
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow