英文:
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
内容帮助有限。如何处理它?
英文:
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.
Below is the response. The body
content is not of much help. How to process it?
答案1
得分: 1
body
这里是一张照片的内容,但以 base64 编码方式表示。你可以直接将其保存为文件。
这是来自 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);
}
}
}
}
英文:
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);
}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论