1

APIを使用してGoogleリーダーにサブスクリプションを追加しようとしていますが、次のエラーが発生します。

実行期限が切れました

サブスクリプションまたはタグのリストを(「get」を使用して)読み取るのに問題はありませんでした。しかし、('post'を使用して)サブを追加しようとするとタイムアウトになります

コードはRubyonRailsで記述されており、HTTPartyを使用してWebサービスとの通信を処理しています。

私のコードは次のとおりです(私はまだRuby / Railsに慣れていないので、以下に含まれる悪い慣行をお詫びします。私にそれらを指摘してもらえてうれしいです):

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

参考までに、これは私がトークンを取得する方法です:

# 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

必要な追加情報を提供させていただきます。

前もって感謝します!

4

1 に答える 1

0

たくさんいじった後、私は解決策を見つけました!

Content-Lengthを「0」に設定するだけで済みました。以前は、ベースにしているPHPクラス( greader.class.php )に従って、「クエリ」の長さに設定していました。他の誰かが同じ問題を抱えている場合に備えて、これについて言及します。

于 2011-05-10T14:50:28.300 に答える