gpt4 book ai didi

ruby - 如何在 ruby​​ 中指定 youtube api 的时间

转载 作者:行者123 更新时间:2023-12-03 05:46:54 25 4
gpt4 key购买 nike

我正在编写 Ruby 脚本来与 Youtube Streaming API 通信创建直播和直播。到目前为止,我已经能够编写代码来插入新的流并且它可以工作,但是我在插入广播时遇到了问题。我收到以下错误:

/usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.8.0/lib/google/api_client.rb:652:in `block (2 levels) in execute!': Scheduled start time is required (Google::APIClient::ClientError)
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-1.4.1/lib/retriable/retry.rb:27:in `perform'
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-1.4.1/lib/retriable.rb:15:in `retriable'
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.8.0/lib/google/api_client.rb:635:in `block in execute!'
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-1.4.1/lib/retriable/retry.rb:27:in `perform'
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-1.4.1/lib/retriable.rb:15:in `retriable'
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.8.0/lib/google/api_client.rb:626:in `execute!'
from ruby_script.rb:44:in `insert_broadcast'
from ruby_script.rb:98:in `<main>'

所以,它提示我没有提到预定的开始时间。以下是相关代码:
# Create a liveBroadcast resource and set its title, scheduled start time,
# scheduled end time, and privacy status.
def insert_broadcast(client, youtube, options)
insert_broadcast_response = client.execute!(
api_method: youtube.live_broadcasts.insert,
parameters: {
part: 'snippet,status'
},
body_object: {
snippet: {
title: options[:broadcast_title],
scheduledStartTime: options[:state_time],
scheduledEndTime: options[:end_time]
},
status: {
privacyStatus: options[:privacy_status]
}
}
)

p "Broadcast: #{insert_broadcast_response.data.id}"
return insert_broadcast_response.id
end

options = {
stream_title: 'stream',
broadcast_title: 'dumdum',
start_time: '2018-01-30T00:00:00.000Z',
end_time: '2018-01-30T00:01:00.000Z',
privacy_status: 'private'
}

我从 this 借来的日期时间格式Python 中的代码示例。我试过 start_time: Time.now希望 Ruby 日期时间对象可以工作,但它没有。我该如何解决这个问题?

编辑 : Here's完整的脚本。

最佳答案

根据@Simple-Lime 的回答修复错字,如果它仍然不起作用,请尝试以下操作:

您需要正确格式化时间:Time.now输出为 2017-07-27 07:35:38 +0000这是错误的。
您需要将其更改为 ISO-8601 标准的日期时间格式,并使用时区的十进制表示法 Time#iso8601 :

require 'time'

# example time format: '2014-01-30T00:00:00.000Z'
Time.now.getutc.iso8601(3)
# => "2017-07-27T07:30:33.742Z"

关于ruby - 如何在 ruby​​ 中指定 youtube api 的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45343386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com