Microsoft OneDrive API InvalidAuthenticationToken CompactToken解析失败,错误代码为:-2147184105 [英] Microsoft OneDrive API InvalidAuthenticationToken CompactToken parsing failed with error code: -2147184105
问题描述
我已经在StackoverFlow和网络上查看了两个类似的问题,但我仍然不知道该怎么办.
I have looked at the two similar questions in StackoverFlow and on the web but I still don't understand what I should do.
我想使用bash脚本(带有curl)以编程方式下载位于OneDrive上的文件.
I want to download a file that is located on OneDrive programmatically using a bash script (with curl).
因此,我在此处看到,我可以使用代码流程以访问Microsoft Graph.因此,我就这样进行了(我从
So I've seen 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
1- I get the code with this 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"
2- Then I swap authorization code for access token with this 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"
然后我将令牌和过期时间存储在文件中
And I store the token and the expire time in a file
3-我做了一些处理来处理我必须刷新令牌(根据到期时间)的事实.
3- I made some process to handle the fact that I have to refresh the token (according to the expire time).
4-我使用令牌通过Microsoft Graph以编程方式下载文件
4- I use my token to download my file programmatically with 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"
api_data=$(curl https://graph.microsoft.com/v1.0/me/drive/items/B8D9948257F95B84%21104/content -H "Authorization: Bearer $access_token")
echo -e "$api_data"
问题-运行程序时,我得到了:
The problem- When I run the program, I get this:
怎么来?
推荐答案
您正在针对错误的端点进行身份验证. login.live.com
端点无法为Graph提供有效的令牌.为此,您需要使用 v2端点.
You're authenticating against the wrong endpoint. The login.live.com
endpoint cannot provide a valid token for Graph. You need to use the v2 Endpoint for this instead.
查看 Microsoft v2终结点入门进行演练.鉴于您正在使用curl,提供的伪代码应该可以为您提供所需的一切.
Check out Microsoft v2 Endpoint Primer for a walkthrough. Given that you're using curl, the pseudo code provided should give you everything you need.
这篇关于Microsoft OneDrive API InvalidAuthenticationToken CompactToken解析失败,错误代码为:-2147184105的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!