2017-11-27 7 views
2

github apiに接続してアカウントに通知するgoプログラムを作成しようとしています。私はreposとinfosをかなり簡単に手に入れることができますが、通知を受け取るのに苦労しています。アカウントに通知があっても配列は常に空です。誰かが私が間違っていることを知っていますか? ありがとうございます!私は最終的に答えを見つけた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)) 

} 

答えて

0

、プログラムが働いている、問題は、私は私のgithubの設定でウェブ上の通知を有効にしなかった、私の側にいた:

は、ここに私のコードです。

関連する問題