586426 ランダム
 HOME | DIARY | PROFILE 【フォローする】 【ログイン】

「東雲 忠太郎」の平凡な日常のできごと

「東雲 忠太郎」の平凡な日常のできごと

【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! --/--
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x
2024.02.26
XML
カテゴリ:Graph API


# アクセストークン取得のための認証情報

$client_id = "YOUR_CLIENT_ID"

$client_secret = "YOUR_CLIENT_SECRET"

$tenant_id = "YOUR_TENANT_ID"

$redirect_uri = "http://localhost"


# アクセストークンを取得するためのパラメータを設定

$authParams = @{

    client_id     = $client_id

    scope         = "https://graph.microsoft.com/.default"

    response_type = "code"

    redirect_uri  = $redirect_uri

}


# ユーザーにログインしてアクセストークンを取得

$authUrl = "https://login.microsoftonline.com/$tenant_id/oauth2/v2.0/authorize?" + ($authParams | foreach { "$($_.Name)=$($_.Value)" })

Start-Process -FilePath $authUrl


# ユーザーによる認証と承認が完了し、リダイレクトされたら、リダイレクトURIからコードを取得します。


# コードを入力

$code = Read-Host -Prompt "Enter the authorization code"


# アクセストークンを取得

$tokenParams = @{

    client_id     = $client_id

    scope         = "https://graph.microsoft.com/.default"

    code          = $code

    redirect_uri  = $redirect_uri

    grant_type    = "authorization_code"

    client_secret = $client_secret

}


$tokenResponse = Invoke-RestMethod -Method Post -Uri "https://login.microsoftonline.com/$tenant_id/oauth2/v2.0/token" -Body $tokenParams


# アクセストークンを取得

$accessToken = $tokenResponse.access_token


if (-not [string]::IsNullOrEmpty($accessToken)) {

    Write-Host "Access Token: $accessToken"


    # 新しい会議の情報

    $meetingSubject = "Meeting"

    $meetingStart = "2024-02-28T09:00:00"

    $meetingEnd = "2024-02-28T10:00:00"

    $meetingLocation = "Conference Room"


    $meetingBody = @{

        subject = $meetingSubject

        start = @{

            dateTime = $meetingStart

            timeZone = "UTC"

        }

        end = @{

            dateTime = $meetingEnd

            timeZone = "UTC"

        }

        location = @{

            displayName = $meetingLocation

        }

        isOnlineMeeting = $true

    } | ConvertTo-Json


    $createMeetingUrl = "https://graph.microsoft.com/v1.0/me/events"

    $createMeetingResponse = Invoke-RestMethod -Uri $createMeetingUrl -Method Post -Headers @{

        Authorization = "Bearer $accessToken"

        'Content-Type' = 'application/json'

    } -Body $meetingBody


    if ($createMeetingResponse) {

        Write-Host "Meeting created successfully. Meeting ID: $($createMeetingResponse.id)"

    } else {

        Write-Host "Failed to create meeting."

    }

} else {

    Write-Host "Failed to retrieve access token."

}







お気に入りの記事を「いいね!」で応援しよう

Last updated  2024.02.26 03:55:17



© Rakuten Group, Inc.