0

google-api-client gem を使用してGoogle Search API for Shoppingにアクセスしようとしています。残念ながら、 Google APIs Consoleで access_token を作成しても認証できないようです。

これが私のコードです:

client = Google::APIClient.new
client.authorization.access_token = "<MY_CONSOLE_ACCESS_TOKEN>"
client.authorization.scope = "https://www.googleapis.com/auth/shoppingapi"

shopping = client.discovered_api("shopping", "v1")
response = client.execute(api_method: shopping.products.list,
                          parameters: { source: "public" })

を表示response.dataすると、エラー メッセージが表示されます。

#<Google::APIClient::Schema::Shopping::V1::Products:0x809d6e14 DATA:{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"authError", "message"=>"Invalid Credentials", "locationType"=>"header", "location"=>"Authorization"}], "code"=>401, "message"=>"Invalid Credentials"}}>

私は何を間違っていますか?

4

1 に答える 1

1

もちろん、投稿して数分でわかります。同じ質問をしている他の人のために何がうまくいったかを共有します。

client = Google::APIClient.new(authorization: nil)
shopping = client.discovered_api("shopping", "v1")
response = client.execute(key: "<MY_ACCESS_TOKEN>",
                          api_method: shopping.products.list,
                          parameters: { source: "public", country: "US" })
于 2012-12-07T17:33:37.503 に答える