-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RefreshToken取得処理と実際に使うフェーズを分けた refs #1
RefreshTokenは事前にLocalで実行してGCSに保存しておいて、後で使う感じにしてみた
- Loading branch information
Showing
6 changed files
with
187 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"golang.org/x/oauth2/google" | ||
"google.golang.org/api/gmail/v1" | ||
"google.golang.org/api/option" | ||
) | ||
|
||
func TestGmailService_Watch(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
clientSecret, err := getCredentialFile(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
config, err := google.ConfigFromJSON(clientSecret, gmail.GmailMetadataScope) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
token := getTokenFromWeb(config) | ||
client := config.Client(ctx, token) | ||
gmailService, err := gmail.NewService(ctx, option.WithHTTPClient(client)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
s, err := NewGmailService(ctx, gmailService) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
resp, err := s.Watch(ctx, "[email protected]", &gmail.WatchRequest{ | ||
TopicName: "projects/sinmetal-ironhead/topics/gmail", | ||
LabelIds: []string{"tbf-stackdriver-notifications"}, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Logf("%#v", resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.