I need some help. Since 2 days, I'm reading several tutorials and trying out code snippets I've found to get an access token from Microsoft to upload a single small file from PHP to OneDrive. This is my current code:
$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' => '******@web.de',
'password' => '123456789',
'scope' => 'https://graph.microsoft.com/Files.ReadWrite'
],
] )->getBody()->getContents() );
}
But its not working... Every time I execute the script, I'm getting different exceptions. I've ended up with this one:
PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST https://login.microsoftonline.com/f8cdef31-a31e-4b4a-93e4-5f571e91255a/oauth2/token resulted in a 400 Bad Request response: {"error":"invalid_request","error_description":"AADSTS90002: Tenant 'web.de' not found. Check to make sure you have the (truncated...)
I don't understand why it's so complicated to just upload a file to OneDrive via PHP.
This is the tutorial I was following: https://www.webshark.ee/how-to-upload-files-from-server-to-microsoft-onedrive-using-rest-api-and-php/