Skip to content

Commit

Permalink
Create main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
alltobebetter authored Jun 21, 2024
1 parent ce49156 commit 70e0e54
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"context"
"fmt"
"log"
"os"

"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/microsoftgraph/msgraph-sdk-go/users"
"github.com/microsoftgraph/msgraph-sdk-go/users/item/messages"

graph "github.com/microsoftgraph/msgraph-sdk-go"
"github.com/microsoftgraph/msgraph-sdk-go/auth"
)

func main() {
clientId := "你的应用程序ID"
tenantId := "你的租户ID"
clientSecret := "你的应用程序机密"

// 创建身份验证提供程序
cred, err := auth.NewClientSecretProvider(tenantId, clientId, clientSecret, []string{"https://graph.microsoft.com/.default"})
if err != nil {
log.Fatalf("创建身份验证提供程序时出错: %v", err)
}

// 创建 Graph 客户端
client := graph.NewGraphClientWithCredentials(cred, nil)

// 获取用户邮件
result, err := client.Users().ByUserId("用户ID").Messages().Request().Get(context.Background())
if err != nil {
log.Fatalf("获取邮件时出错: %v", err)
}

// 打印邮件主题
for _, message := range result.GetValue() {
fmt.Println(*message.GetSubject())
}
}

0 comments on commit 70e0e54

Please sign in to comment.