我想通过我调用 Graph API V1.0 的 powershell 脚本下载 O365 激活报告。我成功获得了令牌,但不知何故无法执行调用来检索 CSV。这是我所做的:
function getToken()
{
param(
)
$global:appreg = @()
$global:appreg +=[pscustomobject]@{tenantId="****";appID="****";secret="****";headers=""}
$global:appreg | % {
$appreg = $_
$ReqTokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
client_Id = $appreg.appID
Client_Secret = $appreg.secret
}
$TokenResponse = iwr -Uri "https://login.microsoftonline.com/$($appreg.tenantId)/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody
$accesstoken = ($TokenResponse | Convertfrom-Json).access_token
$appreg.headers = @{'Authorization' = 'Bearer ' + $accesstoken;'Content-type' = 'application/json'}
#$accesstoken
}
}
$global:getcallurl = "https://graph.microsoft.com/v1.0/reports/getOffice365ActivationsUserDetail"
$mainTenandID = "****"
getToken
到这里为止没有显示错误,所以我假设 getToken 有效
$result = iwr -uri "https://graph.microsoft.com/v1.0/reports/getOffice365ActivationsUserDetail" -Method Get -Headers ($global:appreg |?{$_.tenantID -eq $mainTenandID}).headers
在此之后我得到:
Invoke-RestMethod :底层连接已关闭:发送时发生意外错误。
我在通话中做错了什么?