2016-11-29 39 views
0

我試圖重現本教程:YouTube API, Version 3 on Rails 爲了將其應用於我自己的項目。但是幾天以來我一直在努力。如何正確使用/配置YT寶石?

起初,我有這個錯誤:

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

我已經:

  • GET ruby和rvm更新了
  • 嘗試了不同版本的yt gem
  • 試過:OpenSSL的:: SSL :: VERIFY_PEER = OpenSSL的:: SSL :: VERIFY_NONE
  • 試過:config.force_ssl =假

捲曲-X GET -H「內容長度:0" -H 「用戶代理:YT ::請求(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

任何幫助,建議將強烈和真誠讚賞。

回答

0

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

答:您所做的請求沒有被批准。更新:更改鍵=到ACCESS_TOKEN =

可能的原因:

https://www.youtube.com/annotations_invideo?key= 

您正在嘗試運行的請求annotations_invideo我不能真正找到任何人的文檔中),你所申請一個API密鑰。 API密鑰只適用於公共數據。 annotations_invideo不是對API的有效請求,也不是您需要驗證的內容。如果您需要進行身份驗證,那麼您需要一個訪問令牌,然後應用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

+0

curl命令是在一個點的建議中的錯誤消息。根據教程(https://www.sitepoint.com/youtube-api-version-3-rails/),該專業版專爲處理YouTube API V3而創建。感謝您的幫助。我會盡力與這個寶石的作者取得聯繫。 – NeimadTL

+0

我使用YT API V3的捲曲結果更新了我的帖子。 – NeimadTL