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

调用MS Graph /me/todo/lists API未返回预期任务列表数据问题

问题:调用MS Graph Todo接口返回客户端配置而非任务列表数据

在Node.js应用中调用MS Graph的/v1.0/me/todo/lists接口,返回的是客户端配置对象,而非预期的任务列表数据结构。已在Outlook中创建任务列表和任务,相关代码如下:

配置文件 default.js

"graphToken": {
    "grantType": "urn:ietf:params:oauth:grant-type:jwt-bearer",
    "resource": "https://graph.microsoft.com",
    "requestedTokenUse": "on_behalf_of",
    "scope": "profile offline_access user.read calendars.read",
    "bearerStartWith": "Bearer "
},
"ms": {
    "graph": {
        "host": "https://graph.microsoft.com",
        "get": "GET",
        "post": "POST",
        "default-scope": "/.default",
        "user-agent": "mycompany/*",
        "me": "/v1.0/me",
        "calendar": "/v1.0/me/calendar",
        "todo":"/v1.0/me/todo",
        "scopes": [
          "profile offline_access user.read calendars.read presence.read presence.read.all tasks.read tasks.readwrite"
        ]
    }
},

index.js 相关代码

MS_GRAPH_TODO_PATH = `${MS_GRAPH_HOST}${config.get('ms.graph.todo')}`;
msal.get('/authorize', processMSALToken, async (req, res, next) => {
    try {
        logger.info('Calling the MS Graph to determine has-access.');
        msGraph = await callMSGraph(req, MS_GRAPH_TODO_PATH, accessToken);
    } catch (err) {
        logger.warn('User does not have access to the MS Graph Service. ' + err);
    }
});

todoService.js 相关代码

export const getTodoList = async (graphToken) => {
    const client = await _getAuthenticatedClient(graphToken);

    const response = client
        .api('/me/todo/lists');
        console.log(response);
    return response;
};

ApiV2.js 相关代码

_router.get('/todo/lists', authenticate, checkGraphToken, asyncHandler(async (req, res) => {
    _logger.debug(`POST ${req.originalUrl}`, req.body);

    try {
        const graphToken = req.graphAccessToken;
        const result = await getTodoList(graphToken);

        res.status(StatusCodes.OK).send(result);
    } catch (error) {
        _logger.error(error);
        throw ((error.status) ? error : new Error(StatusCodes.INTERNAL_SERVER_ERROR, _defaultErrorMsg, error.message));
    }
}));

问题定位与修复

问题核心在于todoService.js的getTodoList函数:仅构建了API请求对象,但未调用发送请求的方法(如.get()),导致返回的是请求配置对象而非实际接口响应数据。

修改后的getTodoList函数:

export const getTodoList = async (graphToken) => {
    const client = await _getAuthenticatedClient(graphToken);

    // 添加.get()方法发送请求并等待异步响应
    const response = await client
        .api('/me/todo/lists')
        .get();
    console.log(response);
    return response;
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 07:54:53