假设我的access_token
和我的TEST_CHANNEL_ID
是正确的,那么此请求是否有效?
我收到404错误,我错过了一些参数吗?
uri = URI.parse("https://www.googleapis.com")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new("/youtube/analytics/v1/reports")
request.body = URI.encode_www_form({"Authorization" => "Bearer #{access_token}", "ids" => "channel==#{TEST_CHANNEL_ID}", "start-date" => "2015-07-01", "end-date" => "2015-07-20", "metrics" => "views"})
response = http.request(request)
值得一提的是,我获得了access_token
refresh_token
授权所有youtube api范围
答案 0 :(得分:1)
如果您将访问令牌作为URL参数传递,则参数的名称应为“access_token”,并且您不需要字符串的“Bearer”部分;它只会是:
request.body = URI.encode_www_form({"access_token" => "#{access_token}", "ids" => "channel==#{TEST_CHANNEL_ID}", "start-date" => "2015-07-01", "end-date" => "2015-07-20", "metrics" => "views"})
如果您在请求标头中设置了访问令牌,则只能使用Authorization: Bearer {whatever}
表单。