我需要一些帮助。自从2天以来,我阅读了一些教程,并尝试了一些代码片段,我发现从微软获得了一个访问令牌,可以从PHP上传一个小文件到OneDrive。这是我当前的代码:
$onedrive_tenant_id = 'f8cdef31-a31e-4b4a-93e4-5f571e91255a';
$onedrive_client_id = '2947eb86-xxxxxx....';
$onedrive_client_secret = '6994277d-xxxxxx....';
if ( ! empty( $onedrive_tenant_id ) && ! empty( $onedrive_client_id ) && ! empty( $onedrive_client_secret ) ) {
$guzzle = new Client();
$url = 'https://login.microsoftonline.com/' . $onedrive_tenant_id . '/oauth2/token';
$user_token = json_decode( $guzzle->post( $url, [
'form_params' => [
'client_id' => $onedrive_client_id,
'client_secret' => $onedrive_client_secret,
'resource' => 'https://graph.microsoft.com/',
'grant_type' => 'password',
'username' => 'muster.mann@web.de',
'password' => '123456789',
'scope' => 'https://graph.microsoft.com/Files.ReadWrite'
],
] )->getBody()->getContents() );
}
但是它不工作…每次执行脚本,都会得到不同的异常。我最终选择了这个:
PHP致命错误:Uncaught GuzzleHttpExceptionClientException:客户端错误:
POST https://login.microsoftonline.com/f8cdef31-a31e-4b4a-93e4-5f571e91255a/oauth2/token
导致400 Bad Request
响应:{"error"invalid_request"error_description":"AADSTS90002:租户没有找到"web.de"。检查是否有(截断的…)
我不明白为什么通过PHP上传文件到OneDrive这么复杂。
这是我所遵循的教程:https://www.webshark.ee/how-to-upload-files-from-server-to-microsoft-onedrive-using-rest-api-and-php/
建议的过程是使用msgraph-sdk-php
这个过程,有一个完整的线索,你正在使用相同的,但需要有更多的扩展。
-
使用PHP web服务创建示例应用程序。必须注意的是,我们需要一个支持单驱动器的开放式office 365帐户。(https://github.com/AI-EVO/PHP-MS-Graph)
-
查看MSGRAPH-SDK-PHP的自述教程
-
通过图形API (https://github.com/microsoftgraph/msgraph-sdk-php#register-your-application)注册步骤1中使用ADD设计的应用程序
-
创建您的权限列表,并检查这些权限的可用性和可访问性。
进一步参考请使用
链接