如何在Microsoft Graph Python SDK中使用odata_next_link遍历分页结果?
Microsoft Graph Python SDK 分页处理方案
针对你遇到的分页问题,直接用SDK客户端的get()方法传入完整的@odata.nextLink URL即可解决,具体步骤如下:
第一次请求用你原来的builder写法获取初始结果:
response = await graph_client.groups.by_group_id(group_id).transitive_members.get() # 这里处理第一页的成员数据,比如自定义process_members函数 process_members(response.value)循环处理后续分页:
while hasattr(response, '@odata.nextLink') and response['@odata.nextLink']: # 直接传入完整的nextLink URL发起请求 next_response = await graph_client.get(response['@odata.nextLink']) # 处理当前页数据 process_members(next_response.value) # 更新response为当前页,继续循环判断是否还有下一页 response = next_response
为什么之前的方法行不通?
你尝试的GroupsRequestBuilder传入skip_token参数报错,是因为SDK生成的请求构建器是强类型的,其GetQueryParameters并没有暴露skip_token这个参数——微软文档要求直接使用完整的@odata.nextLink,而不是拆分出token单独使用,所以直接用客户端的get()方法调用完整URL是符合官方规范的正确做法。
内容的提问来源于stack exchange,提问作者scubbo
相关产品推荐
相关产品推荐

