thibaudgg / video_info

Get video info from Dailymotion, Vimeo, Wistia, and YouTube URLs.

Home Page:https://rubygems.org/gems/video_info

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YouTube - Title & Description Scrape Error

bearded-avenger opened this issue · comments

Hey, thanks for the work on this gem. Really helpful.

I think something may have changed with YouTube, as the title and description now error. I was using the HTML scraper version, but tried with an API key and I get the same result. It happens with multiple videos, ruling out a single video issue.

When not using an API key, the error returned is:

undefined method `value' for nil:NilClass
video_info (2.7) lib/video_info/providers/youtube_scraper.rb:63:in `block in meta_node_value'

When I use an API key it returns nil.

Here's a full example:

 => #<VideoInfo:0x00007fe5bb4190a8 @provider=#<VideoInfo::Providers::Youtube:0x00007fe5bb4183d8 @options={"User-Agent"=>"VideoInfo/2.8.0"}, @url="http://www.youtube.com/watch?v=mZqGqE0D0n4", @video_id="mZqGqE0D0n4">> 
2.6.2 :007 > VideoInfo::VERSION
 => "2.8.0" 
2.6.2 :008 > video.title
vid => nil 
2.6.2 :009 > video.description
video => nil 
2.6.2 :010 > video.video_id
 => "mZqGqE0D0n4" 
2.6.2 :011 > ```


VideoInfo Version - 2.8.0
Ruby Version - 2.6.2

Hi @bearded-avenger, thanks for the issue, it certainly possible that Youtube changed something.

I'm not actively maintaining this gem, but pull requests to fix such issues are definitely welcomed. Please let me know if you need some help to submit one.

I can help with this one

Hi @bearded-avenger, thanks for the issue.

It seems like an extra step is necessary for Youtube now.

Besides generating the API key, it is necessary to enable the YouTube Data API for the project which your API key was generated. You can enable it here:
https://console.developers.google.com/apis/library/youtube.googleapis.com

Before enabling it for my project, I was getting this error too:

curl "https://www.googleapis.com/youtube/v3/videos?id=mZqGqE0D0n4&part=snippet,statistics,status,contentDetails&fields=items(id,snippet,statistics,status,contentDetails)&key=<api_key>"

{
  "error": {
    "code": 403,
    "message": "YouTube Data API v3 has not been used in project 239085110097 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=239085110097 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "errors": [
      {
        "message": "YouTube Data API v3 has not been used in project 239085110097 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=239085110097 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
        "domain": "usageLimits",
        "reason": "accessNotConfigured",
        "extendedHelp": "https://console.developers.google.com"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}

No code changes are necessary, but I'll add this extra step to the Readme

Hi @bearded-avenger!

V3 has been released, solving this issue 🎉