我试过用
the library from krizalys
用于实现从OneDrive读取和写入文件。它应该适用于商业账户,但如果它也适用于个人账户,那就更好了。
因为我读到krizalys示例中使用的live sdk很快就会离线(
as mentioned here
,我尝试实现Microsoft Graph。
目前我实现了两种获取访问令牌的方法,一种是授予类型
password
(
getAccessToken Method from this sample used
)和一个
client_credentials
(就像在
krizalys lib
)两者似乎都有效,并返回一个
access_token
和
refresh_token
,但当我尝试提出请求时,我会收到消息:
“InvalidAuthenticationToken[Message]=>访问令牌为空”
我请求的代码:
$data = array("name" => "test");
$url = "https://graph.microsoft.com/v1.0/me/drive/root";
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $url, [
'headers' => [
'Authorization: Bearer ' . $this->_state->token->data->access_token,
'Content-Type: application/json',
'Content-Length: ' .strlen(json_encode($data))
],
'body' => json_encode($data),
]);
我还用get方法尝试了它,并添加了
Host: graph.microsoft.com
为了确保这不是问题:
$url = "https://graph.microsoft.com/v1.0/me";
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $url, [
'headers' => [
'Authorization: Bearer ' . $this->_state->token->data->access_token,
'Host: graph.microsoft.com'
],
]);
令牌响应负载如下所示:
应用程序配置在
https://apps.dev.microsoft.com
设置权限。我的要求有什么问题吗?我不知道为什么我总是
InvalidAuthenticationToken
消息。谢谢。