假设我的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范围
如果你将访问令牌作为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}
表单。
这是相关文档