全て
| カテゴリ未分類
| 通常
| 数学
| 投資
| 副業
| 転職・就職
| ブログ
| 株Stock
| VBA
| SharePoint
| REST API
| RenderListDataAsStream
| PowerAutomateDesktop
| Graph API
| PowerApps
| PowerAutomate
| PowerFx
| OfficeScriptオフィススクリプト
| PowerAutomate日時Excel日時相互関係
| PowerShell
| Dataverse
| UiPath
| OneDrive
| LINQ
| VB.NET
| C#.NET
| WPFC#.NET
| Git
カテゴリ: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/Files.ReadWrite.All" 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/Files.ReadWrite.All" 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" # 共有するファイルの ID $fileId = "YOUR_FILE_ID" # 共有先のユーザーのメールアドレス $shareEmailAddress = "recipient@example.com" # 共有の設定 $shareBody = @{ recipients = @( @{ emailAddress = @{ address = $shareEmailAddress } } ) message = "This is the shared file." requireSignIn = $false sendInvitation = $true } | ConvertTo-Json $shareFileUrl = "https://graph.microsoft.com/v1.0/me/drive/items/$fileId/createLink" $shareFileResponse = Invoke-RestMethod -Uri $shareFileUrl -Method Post -Headers @{ Authorization = "Bearer $accessToken" 'Content-Type' = 'application/json' } -Body $shareBody if ($shareFileResponse) { Write-Host "File shared successfully. Shared link: $($shareFileResponse.link.webUrl)" } else { Write-Host "Failed to share file." } } else { Write-Host "Failed to retrieve access token." } お気に入りの記事を「いいね!」で応援しよう
Last updated
2024.02.26 03:43:46
[Graph API] カテゴリの最新記事
|