ruby-on-rails-4 - 如何正确使用/配置 YT gem?

标签 ruby-on-rails-4 youtube rubygems youtube-api

我正在尝试重现本教程:YouTube API, Version 3 on Rails
为了将它应用到我自己的项目中。但是从这几天开始我就很难受。

起初,我有这个错误:

A request to YouTube API caused an unexpected server error: To display more verbose errors, change the configuration of Yt with: Yt.configure do |config| config.log_level = :debug end



我更新了 RVM 和 Ruby,现在我收到了这个错误:

Yt::Errors::Forbidden in VideosController#create A request to YouTube API was considered forbidden by the server: To display more verbose errors, change the configuration of Yt with: Yt.configure do |config| config.log_level = :debug end



我已经 :
  • 更新 ruby​​ 和 rvm
  • 尝试了不同版本的 yt gem
  • 试过了: OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
  • 试过了:config.force_ssl = false



  • curl -X GET -H“内容长度:0”-H“用户代理:Yt::Request (gzip)”-H“主机:www.googleapis.com”“https://www.googleapis.com/youtube/v3/videos?id=wuZfOIWwM_Y&part=snippet

    返回:

    curl result

    使用 Rails 4.2.4、Ruby 2.3.0;
    源代码位于:https://github.com/NeimadTL/YT_Sample_App

    任何帮助和建议都将受到强烈和真诚的赞赏。

    最佳答案

    forbidden (403) forbidden Access forbidden. The request may not be properly authorized.



    答:您提出的请求未经授权。更新:将 key= 更改为 access_token=

    可能原因:
    https://www.youtube.com/annotations_invideo?key=
    

    您正在尝试运行请求 annotations_invideo (我实际上在文档中找不到任何内容)并且您正在对其应用 API key 。 API key 仅适用于公共(public)数据。 annotations_invideo不是对 API 的有效请求,也不是您需要对其进行身份验证的东西。如果您需要进行身份验证,那么您将需要一个访问 token ,然后应用 access_token=而不是 key=
    你到底在哪里找到 annotations_invideo ?

    更新:

    对我来说幸运的是,自从你发布你的问题以来,我能够接受不到一个小时
    https://www.youtube.com/annotations_invideo?access_token=AIzaSyBSvIOM0EGX1tcrf5IAlYJuH_ttqVgTO4Q&video_id=BPNYv0vd78A
    

    并将其转储到返回数据的网络浏览器中。
    <document>
    <annotations>
    <annotation author="" id="annotation_1585555999" log_data="ei=B2k9WIOCB8X0dNKokKAG&a-id=annotation_1585555999&xble=1&a-type=4&a-v=BPNYv0vd78A" style="title" type="text">
    <TEXT>Hello, world!</TEXT>
    <segment>
    <movingRegion type="rect">
    <rectRegion d="0" h="25.2779998779" t="0:00.000" w="75.0" x="13.1540002823" y="67.3239974976"/>
    <rectRegion d="0" h="25.2779998779" t="0:02.089" w="75.0" x="13.1540002823" y="67.3239974976"/>
    </movingRegion>
    </segment>
    <appearance bgAlpha="0.25" bgColor="0" borderAlpha="0.10000000149" effects="" fgColor="16777215" fontWeight="bold" highlightFontColor="16777215" textSize="21.6642"/>
    </annotation>
    <annotation id="channel:563d3ce4-0000-20cc-8fd5-001a11463304" style="playlist" type="promotion" log_data="ei=B2k9WIOCB8X0dNKokKAG&a-type=12&a-ch=UCwCnUcLcb9-eSrHa_RQGkQQ&xble=1&a-id=563d3ce4-0000-20cc-8fd5-001a11463304&l-class=2&link-id=PLuW4g7xujBWfU26JUTW1DGs3hk4LD5KaL&a-v=BPNYv0vd78A">
    <data>
    {"playlist_length":"200","session_data":{"itct":"CAIQwTcY____________ASITCMOh497wzdACFUU6HQodUhQEZCj4HTICaXZIwN_33vSX1vkE","annotation_id":"563d3ce4-0000-20cc-8fd5-001a11463304","feature":"iv","ei":"B2k9WIOCB8X0dNKokKAG","src_vid":"BPNYv0vd78A"},"is_mobile":false,"text_line_2":"Adorable Kids","text_line_1":"Check this playlist","image_url":"https:\/\/i.ytimg.com\/vi\/yDrLVqRHAsw\/mqdefault.jpg","start_ms":1000,"collapse_delay_ms":86400000,"end_ms":3000}
    </data>
    <segment/>
    <action trigger="click" type="openUrl">
    <url type="hyperlink" target="new" value="https://www.youtube.com/watch?v=yDrLVqRHAsw&list=PLuW4g7xujBWfU26JUTW1DGs3hk4LD5KaL"/>
    </action>
    </annotation>
    </annotations>
    </document>
    

    注意:我想知道为什么这是返回 XML 而不是 Json 它让我认为这是一个较旧的 api。发现您正在使用 YouTube API v2,它是 deprecated它应该被关闭。

    https://youtube-eng.googleblog.com/2014/09/have-you-migrated-to-data-api-v3-yet.html

    您应该放弃它并移至 YouTube API v3

    关于ruby-on-rails-4 - 如何正确使用/配置 YT gem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40864666/

    相关文章:

    ruby-on-rails - 通过地理编码器获取当前位置。 rails

    youtube - React-native-video 播放 Vimeo 和 YouTube

    ffmpeg 使用 rtmp 无限流式传输音频和视频

    mysql - 事件记录 ruby​​ on rails 错误

    rubygems - 使用 SublimeCodeIntel 和 RVM 在 Sublime Text 2 中自动完成以使用 Ruby Gems

    ruby-on-rails - 带有 devise 和 devise_token_Auth 的路由不起作用

    ruby-on-rails - Rails 4 - 查找嵌套属性,选择某些子项

    javascript - YouTube iframe API : can't make it responsive

    ruby-on-rails - 从 Ruby on Rails 开始。在指定要下载的版本时,Gemfile 和 gems 是如何工作的?

    javascript - Rails 500 服务器错误