title: Uploading videos to YouTube w/ Ruby and v3 API results in Unauthorized error
body: <p>I'm trying to create a service which will upload videos to my client's YouTube account. </p>
  
  <p>Here's what I've done so far:</p>
  
  <ul>
  <li>I'm using Google Ruby gems - <code>googleauth</code> and <code>google-api-client</code> - and have the "service account" set up.</li>
  <li>I've set the <code>GOOGLE_APPLICATION_CREDENTIALS</code> environment variable to point to the downloaded json file provided when setting up the service account</li>
  <li>I'm requiring the correct library: <code>google/apis/youtube_v3</code></li>
  </ul>
  
  <p>Here's the code:</p>
  
  <pre><code>class Video &lt; ActiveRecord::Base
  
    def upload_to_youtube!(force=false)
      if self.youtube_key.blank? || force
        yt = Google::Apis::YoutubeV3::YouTubeService.new
        scopes =  [
          "https://www.googleapis.com/auth/youtube", 
          "https://www.googleapis.com/auth/youtube.force-ssl", 
          "https://www.googleapis.com/auth/youtube.upload"
        ]
        authorization = Google::Auth.get_application_default(scopes)
        yt.authorization = authorization
  
        title = "Clever Title"
        description = "Lorem ipsum dolor"
        file_path = "/path/to/mp4/file.mp4"
  
        metadata = {
          snippet: {
            title: title,
            description: description,
          },
        }
  
        yt.insert_video("id", metadata, upload_source: file_path, content_type: "video/mp4", options: {retries: 3})
      else
        true
      end
    end
  end
  </code></pre>
  
  <p>When running this, I get the following error:</p>
  
  <pre><code>Sending upload start command to https://www.googleapis.com/upload/youtube/v3/videos?part=id
  Upload status final
  Error - #&lt;Google::Apis::AuthorizationError: Unauthorized&gt;
  
  Retrying after authentication failure
  Sending upload query command to
  Error - #&lt;NoMethodError: undefined method `+' for nil:NilClass&gt;
  
  NoMethodError: undefined method `+' for nil:NilClass
  from /Users/samullen/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:1532:in `addr_port'
  </code></pre>
  
  <p>I'm at a loss and I'm running out of time. I don't know if there's something else with OAuth I need to do, a sacrifice which needs to be made, or a jig that needs to be danced. I'm just stumped. </p>