尽管手动请求工作正常,但无法使用 yt gem 读取标题 [英] unable to read title with yt gem though manual request works fine
问题描述
我对 ruby on rails 还很陌生.我正在尝试使用 yt gem 来获取 youtube 视频的详细信息.我看到以下问题.
对 YouTube API 的请求导致了意外的服务器错误:{} 您可以通过运行以下命令手动重试相同的请求:curl -X GET -H "content-length: 0" -H "user-agent: Yt::请求 (gzip)"
当我手动访问 API URL 时,我得到了预期的详细信息.
这是我的文件和代码.
articles_contoller
def 索引@article = Article.all@campaign = Campaign.all@video = Yt::Video.new 网址:'https://www.youtube.com/watch?v=5Tzg9173xC4'@title = @video.title结尾
index.html.erb
手动响应 API 调用
"kind": "youtube#videoListResponse","etag": "\"q5k97EMVGxODeKcDgp8gnMu79wM/REiwRaaIO10kgiEe8tHbpNZgd4g\"",页面信息":{总结果":1,每页结果":1},项目": [{"kind": "youtube#video","etag": "\"q5k97EMVGxODeKcDgp8gnMu79wM/wYDY_ffgX0ztxRb89MdmYL7kALY\"","id": "5Tzg9173xC4",片段":{"publishedAt": "2015-03-04T09:21:18.000Z","channelId": "UCgZ-2dsrFfrWCskNEwTNFPQ","title": "Anits ECE Flashmob 2k15",描述": "",缩略图":{默认": {"url": "https://i.ytimg.com/vi/5Tzg9173xC4/default.jpg",宽度":120,高度":90},中等的": {"url": "https://i.ytimg.com/vi/5Tzg9173xC4/mqdefault.jpg",宽度":320,高度":180},高的": {"url": "https://i.ytimg.com/vi/5Tzg9173xC4/hqdefault.jpg",宽度":480,高度":360}},"channelTitle": "anits ece","categoryId": "22","liveBroadcastContent": "无",本地化":{"title": "Anits ECE Flashmob 2k15",描述": ""},"defaultAudioLanguage": "en"}}]
我确定我可能遗漏了一些愚蠢的东西.试图通过查看各种论坛和教程来解决,但没有运气.
感谢您的帮助
解决方案 我现在遇到了同样的问题 - 好运吗?
<小时>更新
我刚刚解决了这个问题 - 对我来说,这是我在使用 SSL 的 localhost 中遇到的错误.
将此行添加到 development.rb
中,然后重试.
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
I am fairly new to ruby on rails. I am trying to use yt gem to get the details of youtube video. I see the following issue.
"A request to YouTube API caused an unexpected server error: {} You can retry the same request manually by running: curl -X GET -H "content-length: 0" -H "user-agent: Yt::Request (gzip)"
When i access API URL manually I get the expected details fine.
here are my files and code.
articles_contoller
def index
@article = Article.all
@campaign = Campaign.all
@video = Yt::Video.new url: 'https://www.youtube.com/watch?v=5Tzg9173xC4'
@title = @video.title
end
index.html.erb
<div class="row">
<iframe width="350" height="250"
src="https://www.youtube.com/embed/<%=@video.id%>" frameborder="0" allowfullscreen>
</iframe>
Response to the API call manually
"kind": "youtube#videoListResponse",
"etag": "\"q5k97EMVGxODeKcDgp8gnMu79wM/REiwRaaIO10kgiEe8tHbpNZgd4g\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"q5k97EMVGxODeKcDgp8gnMu79wM/wYDY_ffgX0ztxRb89MdmYL7kALY\"",
"id": "5Tzg9173xC4",
"snippet": {
"publishedAt": "2015-03-04T09:21:18.000Z",
"channelId": "UCgZ-2dsrFfrWCskNEwTNFPQ",
"title": "Anits ECE Flashmob 2k15",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/5Tzg9173xC4/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/5Tzg9173xC4/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/5Tzg9173xC4/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "anits ece",
"categoryId": "22",
"liveBroadcastContent": "none",
"localized": {
"title": "Anits ECE Flashmob 2k15",
"description": ""
},
"defaultAudioLanguage": "en"
}
}
]
I am sure i might be missing something silly. Tried to solve by looking various forums and tutorials but no luck.
Appreciate your help
解决方案 I'm having the same issue right now - any luck?
Update
I just fixed the issue - for me it was an error I get in localhost, with SSL.
Add this line to development.rb
and then try again.
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
这篇关于尽管手动请求工作正常,但无法使用 yt gem 读取标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文