Question

J'essaie d'ajouter un abonnement à Google Reader, en utilisant son API, mais j'obtiens l'erreur suivante:

L'exécution a expiré

Je n'ai eu aucun problème à lire (en utilisant «get») une liste d'abonnements ou de balises. Mais cela met en période quand j'essaie d'ajouter un sous-marin (en utilisant «post»)

Le code est écrit en Ruby sur Rails et j'utilise Httparty pour gérer la communication avec le service Web.

Mon code est le suivant (je suis encore nouveau dans Ruby / Rails, désolé pour toutes les mauvaises pratiques incluses ci-dessous. Je suis plus qu'heureux de les faire signaler):

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

Pour référence, c'est ainsi que j'obtiens le jeton:

# 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

Je serais heureux de fournir toute information supplémentaire requise.

Merci d'avance!

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top