【问题标题】:Show/edit a file on onedrive with microsoft graph使用 microsoft graph 在 onedrive 上显示/编辑文件
【发布时间】:2021-06-03 16:18:46
【问题描述】:

我想在 onedrive 上使用 json 文件来保存和编辑那里的数据。我从 microsoft graph 复制到这里: https://graph.microsoft.com/v1.0/me/drive/root/search(q='finance')?select=name,id,webUrl 但这不起作用,如果我想将它记录到控制台中。这是我第一次使用 api。希望在这里得到帮助。

【问题讨论】:

    标签: html microsoft-graph-api onedrive microsoft-graph-sdks


    【解决方案1】:

    如果您刚开始使用 Microsoft Graph,请查看 Graph Explorer https://aka.ms/ge。这是一个在线游乐场,您可以在其中尝试查询或探索 Microsoft Graph 的大量示例。

    要在 OneDrive 中处理文件,您需要使用 DriveItem 实体:https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0

    要使用 DriveItem 元数据,您可以执行 UpdateItem https://docs.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0&tabs=http,在其中创建需要更新的项目的所有属性的 JSON 集合,如下所示

    PATCH /me/drive/items/{item-id}
    Content-type: application/json
    
    {
      "name": "new-file-name.docx"
    }
    

    要使用 DriveItem 内容,您需要执行上传操作https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0

    以下是文档中的两个示例:

    上传新文件

    PUT /me/drive/root:/FolderA/FileB.txt:/content
    Content-Type: text/plain
    
    The contents of the file goes here.
    

    更新现有文件

    PUT /me/drive/items/{item-id}/content
    Content-Type: text/plain
    
    The contents of the file goes here.
    

    【讨论】:

    • 好的,但是我必须在哪里登录我的微软帐户?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多