Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 谷歌购物API-Ruby_Ruby On Rails_Ruby_Api_Google Api_Google Shopping - Fatal编程技术网

Ruby on rails 谷歌购物API-Ruby

Ruby on rails 谷歌购物API-Ruby,ruby-on-rails,ruby,api,google-api,google-shopping,Ruby On Rails,Ruby,Api,Google Api,Google Shopping,我正在用Ruby与Google Api进行集成 我正在使用GoogleAPI客户端gem,但我在授权请求方面遇到了一些问题 我的代码: client_secrets = Google::APIClient::ClientSecrets.load('client_secret_xxxx-.apps.googleusercontent.com.json') auth_client = client_secrets.to_authorization auth_client.update!(:sco

我正在用Ruby与Google Api进行集成

我正在使用GoogleAPI客户端gem,但我在授权请求方面遇到了一些问题

我的代码:

client_secrets = Google::APIClient::ClientSecrets.load('client_secret_xxxx-.apps.googleusercontent.com.json')

auth_client = client_secrets.to_authorization

auth_client.update!(:scope => 'https://www.googleapis.com/auth/content')  #its possible pass a url to redirect and we can fetch do token

auth_uri = auth_client.authorization_uri.to_s

p auth_uri
这段代码返回给我谷歌购物api授权的url

在我授予权限后,我将在此处复制令牌:

token = 'token'
merchant_id = 'xxx'
list_products_url = "https://www.googleapis.com/content/v2/#{merchant_id}/products?key=#{token}"
response = HTTParty.get(list_products_url)
这将向我返回如下错误消息:

#<HTTParty::Response:0x7fde5c37b8f0 parsed_response={"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"required", "message"=>"Login Required", "locationType"=>"header", "location"=>"Authorization"}], "code"=>401, "message"=>"Login Required"}}, @response=#<Net::HTTPUnauthorized 401 Unauthorized readbody=true>, @headers={"vary"=>["Origin", "X-Origin"], "www-authenticate"=>["Bearer realm=\"https://accounts.google.com/\""], "content-type"=>["application/json; charset=UTF-8"], "date"=>["Wed, 24 Feb 2016 14:58:17 GMT"], "expires"=>["Wed, 24 Feb 2016 14:58:17 GMT"], "cache-control"=>["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=1"], "alt-svc"=>["quic=\":443\"; ma=2592000; v=\"30,29,28,27,26,25\""], "connection"=>["close"], "transfer-encoding"=>["chunked"]}>
{“errors”=>[{“domain”=>“global”、“reason”=>“required”、“message”=>“Login required”、“locationType”=>“header”、“location”=>“Authorization”}]、“code”=>401、“message”=>“Login required”}、@response=\35;、@headers={“vary”=>[“Origin”、“X-Origin”]、“www-authenticate”=>[“bear realm=\”https://accounts.google.com/\“”],“内容类型”=>[“应用程序/json;字符集=UTF-8”],“日期”=>[“Wed,2016年2月24日14:58:17 GMT”],“过期”=>[“Wed,2016年2月24日14:58:17 GMT”],“缓存控制”=>[“private,max age=0”],“x-content-type-options”=>[“nosniff”],“x-frame-options”=>[“SAMEORIGIN”],“x-xss-protection”=>[“1;mode=block”],“服务器”=>[“GSE”],“备用协议”=>,“alternate-protocol”=>[“quic=\”:443\“ma=2592000;v=\“30,29,28,27,26,25\”],“连接”=>[“关闭”],“传输编码”=>[“分块”]}>
我不知道我做错了什么

我正在尝试实现这个简单的示例

致意