Accessing a Word(.docx) file's content with Microsoft Graph REST API?

余生长醉 提交于 2020-03-25 18:39:18

问题


Is there a way to obtain the content of a Word document stored in the cloud through the Microsoft Graph API without having to download the file locally?

The goal is to build an app that analyzes a Word document's inner content and produce some interesting data from it. However after searching through Microsoft's Dev Center, Graph Explorer, and their API's documentation repository, I can't find any API endpoints that can serve me that data.

I can find some endpoints that deal with manipulating Excel's contents, but not one that deals with Word. Does Microsoft Graph not support retrieving a Word document's content?

EDIT: For example, I know I can read the contents of a "message" and even apply a search on it through query parameters, as demonstrated by one of Microsoft's samples. But I can't seem to find how to do this with Word documents.


回答1:


Well, it's possible to download the content of the document. See: Download the contents of a DriveItem.

For example:

GET /v1.0/me/drive/root:/some-folder/document.docx:/content

But you'll get the entire docx, with embedded images and all. Don't know if this is what you are looking for.


As an example, see the helix-word2md project that fetches a docx and converts it to markdown.




回答2:


I'm afraid you can't direly access word content. What you can do is use web URL property of a DriveItem opening a document the associated Word Online or native world if it is installed. You can use this below to show specific item or all items:

GET /users/{userId}/drive/items/{itemId}
GET me/drive/root/children/

This is the result below:

{
    "@microsoft.graph.downloadUrl": "",
    "createdDateTime": "2018-08-10T01:43:00Z",
    "eTag": "\"{00000000-3E94-4161-9B82-0000000},2\"",
    "id": "00000000IOJA4ONFB6MFAZXARX7L7RU4NV",
    "lastModifiedDateTime": "2018-08-10T01:43:00Z",
    "name": "daily check.docx",
    "webUrl": "https://xxxxxxx",
    "cTag": "\"c:{00000000-3E94-4161-9B82-37FAFF1A71B5},2\"",
    "size": 26330,
    "createdBy": {
        "user": {
            "email": "000000.onmicrosoft.com",
            "id": "000000-93dc-41b7-b89b-760c4128455a",
            "displayName": "Chris"
        }
    },
    "lastModifiedBy": {
        "user": {
            "email": "0000@0000.onmicrosoft.com",
            "id": "00000000-93dc-41b7-b89b-00000000",
            "displayName": "Chris"
        }
    },
    "parentReference": {
        "driveId": 
   "b!000000000gdQMtns72t31yqWMhnFCjmCqO3tR5ypOf17NKl2USqo1bNqhOzrZ",
        "driveType": "business",
        "id": "00000VN6Y2GOVW7725BZO354PWSELRRZ",
        "path": "/drive/root:"
    },
    "file": {
        "mimeType": "application/vnd.openxmlformats- 
   officedocument.wordprocessingml.document",
        "hashes": {
            "quickXorHash": "OSOK7r2hIVSeY1+FjaCnlOxn2p8="
        }
    },
    "fileSystemInfo": {
        "createdDateTime": "2018-08-10T01:43:00Z",
        "lastModifiedDateTime": "2018-08-10T01:43:00Z"
    }
}


来源:https://stackoverflow.com/questions/51774488/accessing-a-word-docx-files-content-with-microsoft-graph-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!