我正在尝试使用Microsoft graph API从我的SharePoint或OneDrive下载一些文件。我只想使用cURL ( C:\windows\systems32\curl,不是invoke-request)和powershell。
我尝试使用来自微软的文档:https://docs.microsoft.com/en-us/graph/auth-v2-service#4-get-an-access-token
然而,语法似乎是关闭的,我一直有一些问题。
下面是我的开始代码(假设您已经在azure门户中设置了一个appid,并获得了client_id、client_secret和租户id):
curl -d 'client_id'='ENTERCLIENTIDHERE' \
-d 'scope'='https://graph.microsoft.com/.default' \
-d 'client_secret'='ENTERCLIENTSECRETHERE' \
-d 'grant_type'='client_credentials' \
'https://login.microsoftonline.com/ENTERTANTANTHERE/oauth2/v2.0/token'
发布于 2021-08-10 03:54:27
下面的代码将帮助你使用你的app id信息中的一个令牌从Microsoft graph api获取一个请求,然后它将为你选择的特定文件或文件夹生成一个url。您还可以修改代码,仅使用cURL和Powershell for windows从Microsoft graph API获取令牌。
#Generating the Token from the microsoft Graph API
$Result = C:\Windows\System32\curl -n -i -H "Host:login.microsoftonline.com" -H "Content-Type:application/x-www-form-urlencoded" -d "client_id=ENTERCLIENTIDHERE&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default&client_secret=ENTERCLIENTSECRETHERE&grant_type=client_credentials" "https://login.microsoftonline.com/ENTERTENANTIDHERE/oauth2/v2.0/token"
$x = $Result[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
$M = $x[16]
$k = $M -split ‘access_token":"’
$Resultk = $k[1]
$ResulO = $Resultk.Substring(0,$Resultk.Length-2)
#Seeing the token in powershell to verify it came up properly
Write-Output $ResulO
#Requesting a download url from your own sharepoint or onedrive
C:\Windows\System32\curl -H "Host:graph.microsoft.com" -H "Authorization:Bearer $ResulO" -H "X-Cookie:token=$ResulO" "https://graph.microsoft.com/v1.0/sites/ENTERSITENAMEORSITEIDHERE/drive/root:/ENTERFILEPATHORFILEHERE?select=id,@microsoft.graph.downloadUrl"
https://stackoverflow.com/questions/68720924
复制相似问题