我目前正在努力争取Microsoft Graph REST-API.
我要做的是列出今天的事件(发生在午夜和午夜之间).从文档中,过滤器功能非常有限.
我目前的陈述如下:
https://graph.microsoft.com/v1.0/me/events?$top=100&$select=*&$filter=start/DateTime ge '2017-10-31T00:00:00' AND end/DateTime le '2017-11-1T00:00:00'&$orderby=start/DateTime ASC
有趣的部分是在这里$filter=start/DateTime ge '2017-10-31T00:00:00' AND end/DateTime le '2017-11-1T00:00:00'使用start和end和检查是否start >= TODAY AND end <= TODAY+1.对于短于1天的日期来说,这一切都很有效.
我现在的问题是如何获得持续时间超过一天的事件,例如start = YESTERDAY和end = NEXT WEEK.这意味着开始日期是在今天之前,结束日期也不包括在此范围内.
如何获得这个活动?
我正在使用 Microsoft Graph 创建一个event. 一切正常,除了它总是以 UTC 创建事件。我正在遵循文档中的示例,但仍然没有运气。
这是帖子的正文:
{
"subject": "My event",
"start": {
"dateTime": "2017-11-03T04:14:31.883Z",
"timeZone": "Eastern Standard Time"
},
"end": {
"dateTime": "2017-11-10T05:14:31.883Z",
"timeZone": "Eastern Standard Time"
}
}
Run Code Online (Sandbox Code Playgroud)
这是回应:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('...')/events/$entity",
"@odata.etag": "W/\"1OZnj8JcDU6yRK1K4rYSNQABJ3X/lw==\"",
"id": "...",
"createdDateTime": "2017-11-03T04:15:13.7075368Z",
"lastModifiedDateTime": "2017-11-03T04:15:13.7231636Z",
"changeKey": "1OZnj8JcDU6yRK1K4rYSNQABJ3X/lw==",
"categories": [],
"originalStartTimeZone": "UTC",
"originalEndTimeZone": "UTC",
"iCalUId": "...",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"subject": "My event",
"bodyPreview": "",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": true,
"seriesMasterId": null, …Run Code Online (Sandbox Code Playgroud) 如何通过 Microsoft Graph API 将成员添加到组?
根据将成员添加到特定组的文档,它需要以下调用:
POST https://graph.microsoft.com/v1.0/groups/{id}/members/$ref
Content-type: application/json
Content-length: 30
{
"@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"
}
Run Code Online (Sandbox Code Playgroud)
我的问题在于这个 API:
https://graph.microsoft.com/v1.0/groups/{id}/members/$ref
Run Code Online (Sandbox Code Playgroud)
{id} => 组 ID,
members => 添加成员到组
现在要添加或发布的用户/成员数据/参数在哪里?
是 "@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"吗?
@odata.id将成员添加到组时,我是否将值作为成员/用户参数发布?
我正在尝试从中读取连接字符串,appsettings.json并且正在使用:
services.AddSingleton(Configuration);
Run Code Online (Sandbox Code Playgroud)
启动时的这一行抛出空值。我对core2.0很陌生。有人可以告诉我缺少什么吗?
我的启动:
public class Startup
{
public static string ConnectionString { get; private set; }
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton(Configuration);
services.AddSingleton<IConfiguration>(Configuration);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
public class CreateController : Controller
{
public IConfiguration _ConnectionString;
public CreateController(IConfiguration configuration)
{
_ConnectionString = configuration;
}
public IEnumerable<string> Get()
{
Markets();
}
public string Markets()
{
using(SqlConnection con = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在asp.net core 2.0应用程序中实现自定义授权策略。
在我的Custom AuthorizationHandler中,我有以下检查:
if (!context.User.Identity.IsAuthenticated)
{
this.logger.LogInformation("Failed to authorize user. User is not authenticated.");
return Task.CompletedTask;
}
// ... More authorization checks
Run Code Online (Sandbox Code Playgroud)
这很有意义,因为未经身份验证的用户无权执行我的控制器操作。
我正在使用JWT承载身份验证,并将其配置如下:
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(cfg =>
{
cfg.RequireHttpsMetadata = false;
cfg.SaveToken = true;
cfg.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = "<issuer>",
ValidAudience = "<audience>",
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(signingKey)),
ValidateLifetime = false
};
});
Run Code Online (Sandbox Code Playgroud)
我还在注册我的授权要求和处理程序(请注意,这些注册发生在上面配置了身份验证之后,以及在我致电之前serivces.AddMVC():
services.AddAuthorization(options =>
{
options.AddPolicy(Constants.AuthorizationPolicies.MyCustomPolicy,
policy => policy.Requirements.Add(new MyCustomRequirement()));
});
services.AddScoped<IAuthorizationHandler, MyCustomAuthorizationHandler>();
Run Code Online (Sandbox Code Playgroud)
这是我的问题,看来我的授权策略在对jwt令牌进行质询和验证之前正在执行,结果是,由于未对用户进行身份验证,所以我的授权策略失败了。 …
Microsoft Graph 是否已经具有 Azure AD B2C 用户 CRUD 的功能?
我发现了这些相关的问题:
但是两者都有 2017 年的答案,所以我想知道是否已经有我不知道的 Microsoft 更新。我仍然没有在我的搜索中找到。
以下是我迄今为止发现的似乎相互冲突的链接(其他问题中也提到了一些链接)。
在(D) 中,它似乎为用户 CRUD 提供了选项,但我不确定它是否仅适用于 Azure AD 而不适用于 Azure AD B2C。
任何帮助表示赞赏。谢谢!
A. Azure AD B2C:使用 Azure AD Graph API(日期:08/07/2017)
https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-devquickstarts -graph-dotnet
它说:您必须使用 Azure AD Graph API 来管理 Azure AD B2C 目录中的用户。这与 Microsoft Graph API 不同。在此处了解更多信息。
B. 对用户的操作 | 图 API 参考(上次更新:2/12/2018)
https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations
它说:我们强烈建议您使用 …
我正在使用外部 .Net Web 应用程序,想知道如何使用 Microsoft Graph 将大文件上传到文档库。我最多可以上传 4mb,但高于它的任何内容都会引发错误。
我知道有一个createUploadSession但是不确定如何实现它。任何帮助将不胜感激。
这是我为成功上传高达 4mb 所做的工作:
string requestUrl =
"https://graph.microsoft.com/v1.0/drives/{mydriveid}/items/root:/" +
fileName + ":/content";
HttpClient Hclient = new HttpClient();
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Put, requestUrl);
message.Content = new StreamContent(file.InputStream);
client.DefaultRequestHeaders
.TryAddWithoutValidation("Content-Type",
"application/json; odata=verbose; charset=utf-8");
HttpResponseMessage Hresponse = await client.SendAsync(message);
//if the response is 200 then read the response and retrive the GUID!
if (Hresponse.IsSuccessStatusCode)
{
responseString = await
Hresponse.Content.ReadAsStringAsync();
JObject jDataRetrieved = JObject.Parse(responseString);
strGuid = jDataRetrieved.SelectToken("eTag").ToString();
}
Run Code Online (Sandbox Code Playgroud) 当发出 GET( https://graph.microsoft.com/v1.0/users/ {{user_id}} /photo/$value) 请求时,响应数据将写入与图像相同的字符
转换为base64后,我尝试了blob格式,但图片没有出现。
路由器.js
router.get('/photo/:id',function (req,res) {
auth.getAccessToken().then(function (token){
let userId = req.params.id;
graph.getUserPhotoData(token, userId).then(function (result) {
res.json(result);
}).catch(function (e) { console.log(e) })
});
});
Run Code Online (Sandbox Code Playgroud)
图.js
function getUserPhoto(token, userId){
return axios({
method : 'get',
url : 'https://graph.microsoft.com/v1.0/users/'+{{user_id}}+'/photo/$value',
headers: {
'Authorization':token,
// 'Content-Type': 'image/jpeg',
},
responseType : 'blob'
})
}
async function getUserPhotoData(token,userId) {
try{
let userPhoto = getUserPhoto(token,userId);
let p = userPhoto.data;
// let photo = new Buffer(userPhoto.data).toString('base64');
return p; //...013O?\u0011?e????|??>?4+?y??\u0017?"Y...
}catch (e) { console.log(e);} …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个全天活动:
let foobar: any = {
"subject": calendarEvent.Title+"v5",
"body": {
"contentType": "HTML",
"content": calendarEvent! || !calendarEvent.Description ? "No Description": calendarEvent.Description,
},
"start": {
"dateTime": calendarEvent.EventDate,
"timeZone": moment.tz.guess(),
},
"end": {
"dateTime": calendarEvent.EndDate,
"timeZone": moment.tz.guess(),
},
"location": {
"displayName": !calendarEvent || !calendarEvent.Location ? "No Location": calendarEvent.Location,
},
"isAllDay": !calendarEvent || !calendarEvent.fAllDayEvent ? false : true,
};
context.msGraphClientFactory.getClient()
.then((client: MSGraphClient) => {
client.api("/me/calendar/events").post(foobar)
.then((content: any) => {
console.log("CalendarService | createCalendarEvent | content: ", content);
});
});
Run Code Online (Sandbox Code Playgroud)
日志:
当我包含“isAllDay”属性时,它会失败并返回 400(错误请求)。
我排除了该属性,它正在创建没有问题的事件。
有什么建议么?
编辑: …
我从这里读到,获取发生在团队或频道范围之外的用户团队聊天(一对一聊天对话),您需要使用此请求
GET /users/id/messages
Run Code Online (Sandbox Code Playgroud)
和 Teams 聊天消息的主题是“IM”。
我现在的问题是是否可以通过 Graph API 向此对话发送新消息,并且该消息将显示在 Teams 应用程序上?
我尝试通过图形 API 回复此消息,但回复消息已发送到 Outlook,而不是在 Microsoft Teams 应用程序中。