【问题标题】:Unable to render OneNote image resource after appending preAuthenticated=true option in OneNote api call在 OneNote api 调用中附加 preAuthenticated=true 选项后无法呈现 OneNote 图像资源
【发布时间】:2020-07-02 03:00:25
【问题描述】:

https://github.com/microsoftgraph/microsoft-graph-docs/issues/2624

我遇到了上述问题。

我正在尝试通过调用https://graph.microsoft.com/v1.0/users/{userId}/onenote/pages/{pageId}/content?preAuthenticated=true 来保存带有图片引用的页面内容

根据这个 - Downloading one note page with image content as HTML

通过在您进行提取时附加“?preAuthenticated=true”,它将使图像公开。

但是当我尝试渲染 html 时,它给了我“加载资源失败:服务器响应状态为 401(未授权)”。

【问题讨论】:

    标签: azure-ad-graph-api onenote onenote-api microsoft-graph-onenote


    【解决方案1】:

    官方文档好像有问题:Get OneNote content and structure with Microsoft Graph

    我们可以看到服务根地址是https://graph.microsoft.com/{version}/{location}/onenote/

    但在此页面上的任何示例中,URL 仍然是https://www.onenote.com/api/v1.0/me/notes

    目前,当您添加?preAuthenticated=true 时,您将在此页面上获得这样一个图片的 URL:

    https://graph.microsoft.com/v1.0/users('{userID}')/onenote/resources/{resourceID}/content?publicAuth=true&mimeType=image/png
    

    但是当你尝试在浏览器中访问它时,你会得到401 error Access token is empty

    解决方法是将 URL 修改为:

    https://www.onenote.com/api/v1.0/resources/{resourceID}/content?publicAuth=true&mimeType=image/png
    

    然后你会得到图像。

    【讨论】:

    • 感谢您的回答,但仍然报错:{ "error": { "code": "20130", "message": "No HTTP resource was found that match the request URI Resource not found ,可能公共链接已过期。尝试新的公共页面内容调用..", "@api.url": "aka.ms/onenote-errors#C20130" } }
    • 我知道。 OneNote api 和 Graph Api 使用不同的令牌。
    • @BenWong 其实?preAuthenticated=true好像换成了Page preview:docs.microsoft.com/en-us/graph/onenote-get-content#page-preview。我已经尝试过,但结果与?preAuthenticated=true 相同。我注意到您自己添加了答案。您可以接受它作为答案,这样这篇文章就可以被视为已完成。
    【解决方案2】:

    【讨论】:

      【解决方案3】:

      有点离题,但我想出了如何让图像呈现。

      https://docs.microsoft.com/en-us/graph/api/resource-get?view=graph-rest-1.0&tabs=http

      当您调用 /onenote/pages/{id}/content 时,图像会引用这样的来源

      src="https://graph.microsoft.com/v1.0/users({userId})/onenote/resources/{resourceId}/$value" 以及 data-src-type="image/jpeg "

      向该端点发出 get 请求,您将获得图像二进制文件,将二进制文件转换为 base64,然后通过将 src 替换为 base64 来呈现 html。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-02
        • 1970-01-01
        相关资源
        最近更新 更多