Search code examples
rubygoogle-cloud-platformgoogle-apigoogle-api-ruby-client

Ruby require - cannot load such file -- google/api_client


I'm trying to write a ruby script to upload youtube videos, but I can't get past this line:

require 'google/api_client'

I get this error:

 `require': cannot load such file -- google/api_client (LoadError)

I am running ruby 3.2.1. In gem list I see this:

google-api-client (0.53.0)

What else do I need to do?

https://developers.google.com/youtube/v3/code_samples/ruby


Solution

  • The documentation that you're looking at references gem version 0.7.0:

    gem 'google-api-client', '>0.7'
    

    Version 0.7.0 was released on January 23rd, 2014. The current version is 0.53.0 and was released January 18th, 2021. The documentation that you are looking at is out of date and will not work with v0.53.0.

    If you look at the documentation for 0.53.0 you'll see that this gem has been deprecated:

    This library is deprecated and will likely not be updated further. Instead, please install the gem corresponding to the specific service you want to use. For example, to use the Google Drive V3 client, install the google-apis-drive_v3 gem. To use the code generator, install the google-apis-generator gem.

    And when you look at the README you can see that they recommend that you find a modern client:

    Google provides two types of Ruby API client libraries: simple REST clients and modern clients.

    The libraries in this repo are simple REST clients. These clients connect to HTTP/JSON REST endpoints and are automatically generated from service discovery documents. They support most API functionality, but their class interfaces are sometimes awkward.

    Modern clients are produced by a modern code generator, combined with hand-crafted functionality for some services. Most modern clients connect to high-performance gRPC endpoints, although a few are backed by REST services. Modern clients are available for many Google services, especially Cloud Platform services, but do not yet support all the services covered by the simple clients. Most modern clients live in the https://github.com/googleapis/google-cloud-ruby repository.

    Unfortunately for you there doesn't appear to be a modern client for YouTube.

    There are multiple simple YouTube clients available in the repo instead such as this client for the v3 API, as well as sample code.

    Separately, there is a gem called yt made by a third-party that may be usable however it has not been updated in two years.