Freigeben über

Cannot request microsoft access token for OneDrive file upload within PHP

Anonym
2022-04-27T10:01:04+00:00

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/
Microsoft 365 und Office | OneDrive | Für Zuhause | Andere

Gesperrte Frage. Diese Frage wurde aus der Microsoft-Support-Community migriert. Sie können darüber abstimmen, ob sie hilfreich ist, aber Sie können keine Kommentare oder Antworten hinzufügen oder der Frage folgen.

0 Kommentare Keine Kommentare

5 Antworten

Sortieren nach: Am hilfreichsten
  1. Anonym
    2022-04-27T11:23:04+00:00

    You can't really contact some a Microsoft developer for support in this way. Probably the best thing is to use the board here:

    https://docs.microsoft.com/en-us/answers/produc...

    Kind Regards,

    Elise

    War diese Antwort hilfreich?

    0 Kommentare Keine Kommentare
  2. Anonym
    2022-04-27T11:18:19+00:00

    Hi Elise,

    how can I contact a Microsoft developer to solve this topic?

    Cheers

    War diese Antwort hilfreich?

    0 Kommentare Keine Kommentare
  3. Anonym
    2022-04-27T11:12:21+00:00

    I believe the API you are using needs access to Azure Active Directory, but you would need to consult with the documentation to confirm this, or a software developer for further assistance.

    Kind Regards,

    Elise

    War diese Antwort hilfreich?

    0 Kommentare Keine Kommentare
  4. Anonym
    2022-04-27T11:01:31+00:00

    Hi Elise,

    so it's not possible to upload into a OneDrive with a personal account?

    Cheers

    War diese Antwort hilfreich?

    0 Kommentare Keine Kommentare
  5. Anonym
    2022-04-27T10:32:14+00:00

    Hi, I'm Elise, and I'd be happy to help with your issue.

    It looks like you might be using a personal account rather then a business account, which is causing this particular issue.

    Kind Regards,

    Elise

    War diese Antwort hilfreich?

    0 Kommentare Keine Kommentare