Get user events with Github API and Octokit

冷暖自知 提交于 2019-12-11 19:53:15

问题


I'm trying to make a simple call to retrieve user events on github through octokit.

According to the docs I create new client and visit the user events endpoint.

client = Octokit::Client.new(access_token: my_token)
user = client.user

Up to here it works fine, now I continue with

events = user.events
=> nil

Alternatively, when I do

client = Octokit::Client.new(access_token: my_token, api_endpoint: 'users/:user/events')

I get

#<Octokit::Client:0x007f9a78ac04f8...

but how to get list of events from there? Here is the official doc https://developer.github.com/v3/activity/events/#list-events-performed-by-a-user


回答1:


I think what you want is

client = Octokit::Client.new(access_token: my_token)
user = client.user
events = client.user_events user.login

It isn't exactly intuitive and I had to read the source. I haven't had a chance to test this yet but there doesn't appear to be a better way.




回答2:


You have a typo:

client = Octokit::Client::new(access_token: my_token)
                        ^^

Should be:

client = Octokit::Client.new(access_token: my_token)
                        ^


来源:https://stackoverflow.com/questions/25717753/get-user-events-with-github-api-and-octokit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!