0

我设法通过代码进行身份验证,甚至能够使用与下面类似的代码检索有关用户许可证的信息。下面的 AddWorkspaceLicense 函数总是返回错误:

"errors": [
      {
        "message": "Invalid JSON payload received. Unexpected token.\nUserID=xxxxxxxxxx\n^",
        "domain": "global",
        "reason": "parseError"
      }
    ],

将 xxxxxx 替换为电子邮件地址中的用户名。我正在发送整个电子邮件地址,它只解析 @ 之前的用户名以解决此错误。

这是我的两个功能。第一个(AddWorkspaceLicense)不起作用。第二个(GetGoogleAcessToken)工作得很好,并使用相同的方法发送谷歌 JSON 数据。两者之间的唯一区别是第二个传递了多个参数,所以也许我的语法在某种程度上是错误的?



function AddWorkspaceLicense ($AuthToken, $UserID, $UserType){
    switch ($UserType){
        "Student"{
            $SKUID = 1010310008
        }
        "Staff"{
            $SKUID = 1010310009
        }
    }

    $ProductID = 101031
    $requestUri = "https://licensing.googleapis.com/apps/licensing/v1/product/$ProductID/sku/$SKUID/user"
    $params = @{
        UserID=$UserID;
    }
    $response = Invoke-RestMethod -Headers @{Authorization = "Bearer $AuthToken"} -Uri $requestUri -Method Post -Body $params -ContentType 'application/json'
    #return $params
}
AddWorkspaceLicense -AuthToken $AuthToken -UserID "(users primary email address)" -UserType "Student"


function GetGoogleAcessToken {
    $RFToken = "Refresh token here"
    $refreshTokenParams = @{
      client_id=$clientId;
        client_secret=$clientSecret;
      refresh_token=$RFToken;
      grant_type="refresh_token";
    }
    $requestUri = “https://www.googleapis.com/oauth2/v4/token”
    $tokens = Invoke-RestMethod -Uri $requestUri -Method POST -Body $refreshTokenParams
    $ExpireDate = (Get-Date).AddMinutes(30)
    $GoogleAccess = New-Object System.Object
    $GoogleAccess | Add-Member -MemberType NoteProperty -Name ExpireDate -Value $ExpireDate
    $GoogleAccess | Add-Member -MemberType NoteProperty -Name Token -Value $tokens.access_token
    Return $GoogleAccess
}


4

0 回答 0