0

Assuming my access_token and my TEST_CHANNEL_ID are correct, shouldn't this request work?

I'm getting a 404 error, am I missing some parameter?

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)

It's worth mentioning that I obtained my access_token with a refresh_token authorized for all youtube api scopes

codercycle
  • 47
  • 1
  • 7

1 Answers1

1

If you're passing the access token as a URL parameter, the name of the parameter should be "access_token" and you don't need the "Bearer" part of the string; it would just be:

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"})

You only use the Authorization: Bearer {whatever}form if you're setting the access token in the request header.

Here's the documentation on this.

jlmcdonald
  • 13,408
  • 2
  • 54
  • 64