locked
Error executing request to Office365 api with error code=400 RRS feed

  • Question


  • I am trying read emails from outlook using oauth 2 in php, but i am getting error as below

    {"error":"invalid_grant","error_description":"AADSTS70000: The provided value for the 'code' parameter is not valid. The code has expired}

    following are my code:

    if (isset($_GET["code"])) {
        echo "hi";
        echo implode(" ", $_SESSION["scopes"]);
         echo "<pre>";print_r($_GET);echo "</pre>";
        $token_request_data = array (
            "grant_type" => "authorization_code",
            "code" => $_GET["code"],
            "redirect_uri" => $_SESSION["redirect_uri"],
            "scope" => implode(" ", $_SESSION["scopes"]),
            "client_id" => $_SESSION["client_id"],
            "client_secret" => $_SESSION["client_secret"]
    
        );
        $body = http_build_query($token_request_data);
        $response = runCurl($_SESSION["authority"].$_SESSION["token_url"], $body);
        $response = json_decode($response);
    
        store_token($response);
        file_put_contents("office_active_user_id.txt", get_user_id());
        file_put_contents("office_access_token.txt", $response->access_token);
        header("Location: " . $_SESSION["redirect_uri"]); 
    }

    please help me


    • Edited by laurelbe Monday, April 30, 2018 11:32 AM
    Monday, April 30, 2018 8:03 AM

All replies

  • Hi laurelbe,

    Thanks for posting in MSDN Forum.

    For your issue related with Office 365 Rest API, I would suggest you go to stackover flow for help.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 1, 2018 5:07 AM