You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Outlook API集成报错求助:unsupported_response_type参数错误排查

Fixing Outlook API unsupported_response_type Error

Hey there, let's work through this Outlook API error you're hitting—those unsupported_response_type and "Expected value is 'code'" messages are super common when setting up OAuth2 flows, so let's break down exactly what's going wrong and how to fix it, focusing on your outlook-demo.js and game.php files.

What's Causing the Error?

This error is straightforward: your OAuth2 authorization request is sending a response_type parameter that Outlook's API doesn't accept for your client configuration. The API explicitly expects code (for the Authorization Code Flow, which is the recommended flow for server-side apps like your WordPress setup), but your code is likely sending a different value (like token for the Implicit Flow) or missing the parameter entirely.

Step-by-Step Fixes for Your Files

1. Check the Authorization Request in game.php (Line 123+)

Look at where you're building the Outlook authorization URL. You need to ensure the response_type parameter is explicitly set to code. Here's what a correct PHP implementation should look like:

// Example authorization URL construction in game.php
$client_id = 'YOUR_AZURE_CLIENT_ID';
$redirect_uri = 'YOUR_APP_REDIRECT_URI'; // Must match Azure AD app config
$authUrl = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?' . http_build_query([
    'client_id' => $client_id,
    'response_type' => 'code', // THIS IS NON-NEGOTIABLE
    'redirect_uri' => $redirect_uri,
    'scope' => 'https://outlook.office.com/mail.read', // Adjust scopes based on your needs
    'state' => uniqid('', true) // Add state for security
]);
  • Double-check that you didn't accidentally set response_type to token or another value.
  • Verify the redirect_uri matches exactly what's configured in your Azure AD app registration (including HTTP/HTTPS and full path).

2. Validate outlook-demo.js Frontend Requests

If your JavaScript is initiating the authorization redirect, make sure it's also using response_type=code in the URL. For example:

// Example in outlook-demo.js
const clientId = 'YOUR_AZURE_CLIENT_ID';
const redirectUri = 'YOUR_APP_REDIRECT_URI';
const authUrl = `https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectUri}&scope=mail.read`;
window.location.href = authUrl;
  • Avoid using response_type=token here—Outlook's API typically restricts the Implicit Flow to specific client types, and your setup is likely configured for the Authorization Code Flow.

3. Double-Check Your Azure AD App Registration

Your client configuration in Azure needs to align with the Authorization Code Flow:

  • Go to the Azure Portal, find your app registration, and navigate to the Authentication tab.
  • Ensure the Authorization code flow option is enabled (for web apps/server-side apps).
  • Confirm your registered redirect URIs match exactly what's in your game.php and outlook-demo.js files.

4. Debugging Tip

Print out the full authorization URL your code generates (use var_dump($authUrl) in PHP or console.log(authUrl) in JS) and inspect the response_type parameter directly. This will quickly tell you if there's a typo or incorrect value being sent.

Final Notes

Once you've updated the response_type to code and confirmed your app registration settings are correct, the error should disappear, and you'll be able to proceed with fetching the authorization code to access Outlook mail data.

内容的提问来源于stack exchange,提问作者ben

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:40:26