注意:在发布之前,我在堆栈溢出中阅读了类似的问题。
嗨,我正在使用谷歌 api-client-v '0.9.8' 较新,我遇到了问题
client_secrets = Google::APIClient::ClientSecrets.load("/home/secrets.json")
@auth_client = client_secrets.to_authorization
@auth_client.update!(
:scope => 'https://www.googleapis.com/auth/calendar',
:access_type => "offline", #will make refresh_token available
:approval_prompt =>'force',
:redirect_uri => 'http://someurl.com'
)
url = @auth_client.authorization_uri
link = "https://accounts.google.com/o/oauth2/auth?#{url.query}"
当您单击链接时,URL将被重定向到将生成代码的页面
@auth_client.code = "generated code"
@auth_client.fetch_access_token!
生成access_token和refresh_token
service = Google::Apis::CalendarV3::CalendarService.new
response = service.list_events('primary',max_results: 10,single_events: true,order_by: 'startTime',time_min: Time.now.iso8601)
这一点问题会出现
dailyLimitExceededUnreg: Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.
仅供参考我在谷歌开发者控制台中启用了谷歌日历 api。
如果有人解决了这个问题,请告诉我。
将@auth_client.fetch_access_token!
存储在变量中(例如 access_code = @auth_client.fetch_access_token!
)
尝试
service = Google::Apis::CalendarV3::CalendarService.new
service.key = access_code # if this does not work try service.authorization = access_code
response = service.list_events('primary',max_results: 10,single_events: true,order_by: 'startTime',time_min: Time.now.iso8601)
如果失败了,我建议看看日历服务的官方谷歌文档(Ruby)