【问题标题】:How to get notifications with the github api using go如何使用 go 通过 github api 获取通知
【发布时间】:2017-11-27 15:54:00
【问题描述】:

我正在尝试编写一个 go 程序来连接到 github api 并在我的帐户上获取通知。我可以很容易地获得有关用户的存储库和信息,但我很难获得通知,即使我的帐户上有通知,数组总是空的。有人知道我做错了什么吗? 提前致谢!

这是我的代码:

package main
import (
    "fmt"
    "log"

    "golang.org/x/net/context"

    "github.com/google/go-github/github"
    "golang.org/x/oauth2"
)

func check(err error) {
    if err != nil {
        log.Fatal(err)
    }
}

/**
 * this function is used to get the repositories of the client
 */
func getRepo(client *github.Client) []*github.Repository {
    ctx := context.Background()

    repos, _, err := client.Repositories.List(ctx, "", nil)

    check(err)

    fmt.Printf("\n%v\n", github.Stringify(repos))

    return repos
}

/**
 * this function is used to get Authentification using a oauth token
 */
func getAuth() *github.Client {
    ctx := context.Background()
    // put your own OAUTH_TOKEN
    ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: "OAUTH_TOKEN"})

    tc := oauth2.NewClient(ctx, ts)
    client := github.NewClient(tc)

    return client
}

/**
 * this function is used to get notification on the client's account
 */
func getNotif(client *github.Client) []*github.Notification {
    ctx := context.Background()

    notifs, resp, err := client.Activity.ListRepositoryNotifications(ctx, "AlexandreMazgaj", "task_app", nil)

    fmt.Printf("Status code of the response: %d\n", resp.StatusCode)
    check(err)

    return notifs
}

func main() {
    // first we get authentification
    client := getAuth()
    // then we get the notifications
    notifs := getNotif(client)

    fmt.Printf("\n%v\n", github.Stringify(notifs))

}

【问题讨论】:

    标签: go github-api


    【解决方案1】:

    我终于找到了答案,程序正在运行,问题出在我这边,我没有在我的 github 设置中启用网络通知。

    【讨论】:

      猜你喜欢
      • 2012-03-05
      • 1970-01-01
      • 2017-06-12
      • 2023-03-15
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多