简体   繁体   中英

Retrieve contacts along with profile pic in batches using 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.

Batch_Request

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

回复

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 :

在此处输入图片说明

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 = "<body value here>";
            byte[] bytes = Convert.FromBase64String(imgBody);
            using (Image image = Image.FromStream(new MemoryStream(bytes)))
            {
                image.Save("d:/test.jpg", ImageFormat.Jpeg);
            }
        }
    }
}

Result : 在此处输入图片说明 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM