Microsoft OneDrive API InvalidAuthenticationToken CompactToken 解析失败,错误代码:-2147184105
Microsoft OneDrive API InvalidAuthenticationToken CompactToken parsing failed with error code: -2147184105
我在 Whosebug 和网上看了两个类似的问题,但我仍然不明白我应该怎么做。
我想使用 bash 脚本(使用 curl)以编程方式下载位于 OneDrive 上的文件。
所以我看到了here that I can use the code flow to access Microsoft Graph. So I proceeded like that (I inspired myself from the Jay Lee answer):
1- 我得到了代码 URL
https://login.live.com/oauth20_authorize.srf?client_id=10c492f9-132a-4079-adae-382dad9d4339&scope=onedrive.readonly&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient
2- 然后我用这个 URL 交换访问令牌的授权码:
curl -X POST https://login.live.com/oauth20_token.srf -d "client_id=${client_id}&redirect_uri=${redirect_uri}&code=${auth_code}&grant_type=authorization_code" --header "Content-Type:application/x-www-form-urlencoded"
然后我将令牌和过期时间存储在一个文件中
3- 我做了一些处理来处理我必须刷新令牌的事实(根据过期时间)。
4- 我使用我的令牌通过 Microsoft Graph 以编程方式下载我的文件
api_data=$(curl https://graph.microsoft.com/v1.0/me/drive/items/B8D9948257F95B84%21104/content -H "Authorization: Bearer $access_token")
echo -e "$api_data"
问题 - 当我 运行 程序时,我得到这个:
怎么会?
您正在对错误的端点进行身份验证。 login.live.com
端点无法为 Graph 提供有效令牌。您需要为此使用 v2 Endpoint。
查看 Microsoft v2 Endpoint Primer 了解演练。鉴于您使用的是 curl,所提供的伪代码应该可以为您提供所需的一切。
我在 Whosebug 和网上看了两个类似的问题,但我仍然不明白我应该怎么做。
我想使用 bash 脚本(使用 curl)以编程方式下载位于 OneDrive 上的文件。
所以我看到了here that I can use the code flow to access Microsoft Graph. So I proceeded like that (I inspired myself from the Jay Lee answer):
1- 我得到了代码 URL
https://login.live.com/oauth20_authorize.srf?client_id=10c492f9-132a-4079-adae-382dad9d4339&scope=onedrive.readonly&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient
2- 然后我用这个 URL 交换访问令牌的授权码:
curl -X POST https://login.live.com/oauth20_token.srf -d "client_id=${client_id}&redirect_uri=${redirect_uri}&code=${auth_code}&grant_type=authorization_code" --header "Content-Type:application/x-www-form-urlencoded"
然后我将令牌和过期时间存储在一个文件中
3- 我做了一些处理来处理我必须刷新令牌的事实(根据过期时间)。
4- 我使用我的令牌通过 Microsoft Graph 以编程方式下载我的文件
api_data=$(curl https://graph.microsoft.com/v1.0/me/drive/items/B8D9948257F95B84%21104/content -H "Authorization: Bearer $access_token")
echo -e "$api_data"
问题 - 当我 运行 程序时,我得到这个:
怎么会?
您正在对错误的端点进行身份验证。 login.live.com
端点无法为 Graph 提供有效令牌。您需要为此使用 v2 Endpoint。
查看 Microsoft v2 Endpoint Primer 了解演练。鉴于您使用的是 curl,所提供的伪代码应该可以为您提供所需的一切。