首页 文章

使用Microsoft Graph从Sharepoint发布图像

提问于
浏览
0

我的公司已经在Sharepoint中为它的新闻制作了一个自定义照片领域 . 我正在尝试使用Microsoft Graph来获取图像,但没有成功 .

这是列描述:

{ 
        "columnGroup": "Page Layout Columns",
        "description": "",
        "displayName": "Thumbnail image",
        "enforceUniqueValues": false,
        "hidden": false,
        "id": "XXXXXXX-XXXX-XXXX-XXX-XXXXXXXXXXXX",
        "indexed": false,
        "name": "PublishingPageImage",
        "readOnly": false,
        "required": false
    },

Microsoft Graph 的文档中写道,您可以提出这样的请求

GET https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items?expand=fields(select=Column1,Column2)

虽然 - 无论我怎么写这个请求,我都无法获得图像字段 .

我最近的尝试就是这个要求:

https://graph.microsoft.com/beta/sites/knowit.sharepoint.com/lists/posts/items?expand=fields(select=PublishingPageImage)

我从微软得到的回应是这样的:

{
"error": {
    "code": "-1, Microsoft.SharePoint.Client.ClientServiceException",
    "message": "Cannot serialize data for type Microsoft.SharePoint.Publishing.Fields.ImageFieldValue.",
    "innerError": {
        "request-id": "f25e4851-0c1b-4061-ad6a-948d38004046",
        "date": "2018-09-17T14:03:01"
    }
}

}

我应该在请求后使用 .value.data.ImageUrl 之类的东西吗?如果我得到一个链接或数据值并不重要 . 在为Microsoft用户调用 /me/ 时,有一个 $value 属性用于获取用户 Profiles 照片 . 这是这样的吗?

1 回答

  • 2

    这取决于图像的存储方式 . 如果是附件,您可以执行以下操作:

    string baseURL = $"https://{spTenant}/_api/web/lists('{ AA.config.listID}')/items({ siteData.Id})/AttachmentFiles";
            string fileName = await GetFileNameAsync(baseURL);
            string getPictureReqUrl = $"{baseURL}('{fileName}')/$value";
            Stream responseStream = await GetPictureAsync(getPictureReqUrl);
    
         private static async Task<Stream> GetPictureAsync(string reqUrl)
        {
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", SPOToken);
            HttpResponseMessage response = await client.GetAsync(reqUrl);
            return await response.Content.ReadAsStreamAsync();
        }
    

    Important! This is not supported by graph yet, but you can use SharePoint Rest API

    如果图片存储在文档库中,则需要使用Drive对象https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/drive

相关问题