使用Graph API分批检索联系人及其个人资料图片

huangapple go评论80阅读模式
英文:

Retrieve contacts along with profile pic in batches using Graph API

问题

使用下面的查询,我们可以使用Microsoft Graph获取联系人的个人资料图片:

https://graph.microsoft.com/v1.0/users/{user-name}/contacts/{id}/photo/$value

使用上面的查询来检索大量联系人需要一些时间。是否有办法分批检索联系人以及其个人资料图片?

借助以下批量请求的帮助,联系人可以成功按批次获取,每批最多20个,但对于个人资料照片,它返回body。我无法处理这个body内容。是否有办法将这个body处理成可以处理的image格式?

如果有任何C# API,将会非常有帮助。

以下是响应。body内容帮助有限。如何处理它?

使用Graph API分批检索联系人及其个人资料图片

使用Graph API分批检索联系人及其个人资料图片

英文:

With the query below, we can get contact's profile pictures using Microsoft Graph:

https://graph.microsoft.com/v1.0/users/{user-name}/contacts/{id}/photo/$value

Using the above query is taking a bit longer time to retrieve a large number of contacts. Is there any way to retrieve the contacts along with the profile picture in batches?

With the help the of below batch request, the contacts are fetched successfully in batches of 20(max), but for the profile photo it returns body. I am not able to process this body content. Is there any way out to process this body into image format which can be processed.

Any C# API, if there, will be much helpful.

使用Graph API分批检索联系人及其个人资料图片

Below is the response. The body content is not of much help. How to process it?

使用Graph API分批检索联系人及其个人资料图片

答案1

得分: 1

body 这里是一张照片的内容,但以 base64 编码方式表示。你可以直接将其保存为文件。

这是来自 Graph API 响应的演示数据:

使用Graph API分批检索联系人及其个人资料图片

使用以下 C# 代码将其保存为图像:

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var imgBody = "<body value here>";
            byte[] bytes = Convert.FromBase64String(imgBody);
            using (Image image = Image.FromStream(new MemoryStream(bytes)))
            {
                image.Save("d:/test.jpg", ImageFormat.Jpeg);
            }
        }
    }
}

结果:
使用Graph API分批检索联系人及其个人资料图片
使用Graph API分批检索联系人及其个人资料图片

英文:

The body here is the content of a photo but base64 encoded. You can save it as a file directly.

This is my demo data from Graph API response :

使用Graph API分批检索联系人及其个人资料图片

Use the c# code below to save it as an image :

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var imgBody = &quot;&lt;body value here&gt;&quot;;
            byte[] bytes = Convert.FromBase64String(imgBody);
            using (Image image = Image.FromStream(new MemoryStream(bytes)))
            {
                image.Save(&quot;d:/test.jpg&quot;, ImageFormat.Jpeg);
            }
        }
    }
}

Result :
使用Graph API分批检索联系人及其个人资料图片
使用Graph API分批检索联系人及其个人资料图片

huangapple
  • 本文由 发表于 2020年1月3日 14:57:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574401.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定