使用Microsoft Graph,我可以从表中访问行,如下所示:
/v1.0/drives/..../workbook/worksheets/Sheet4/tables/2/rows
Run Code Online (Sandbox Code Playgroud)
该文件规定:
此方法支持OData查询参数以帮助自定义响应.
我是能够使用$select的查询参数:
/v1.0/drives/..../workbook/worksheets/Sheet4/tables/2/rows?$select=values.
Run Code Online (Sandbox Code Playgroud)
但是我如何使用$search或$filter查询参数?例如,我想搜索列'employeeName'包含字符串的行"John".
我试图在我的网络API中使用[FromQuery],我不知道如何使用它.
这是控制器中的GetAllBooks()方法:
[HttpGet]
[Route("api/v1/ShelfID/{shelfID}/BookCollection")]
public async Task<IActionResult> GetAllBooks(string shelfID, [FromQuery] Book bookinfo)
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
这是Book模型类:
public class Book
{
public string ID{ get; set; }
public string Name{ get; set; }
public string Author { get; set; }
public string PublishDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我很困惑这是否是使用[FromQuery]的正确方法.我以为URL是
https://localhost:xxxxx/api/v1/ShelfID/{shelfID}/BookCollection/IActionResult?ID="123"&Name="HarryPotter"
但是断点并没有达到我的控制器方法,所以我想也许URL不正确.有什么建议?谢谢!
我有一个用C#编写的控制台应用程序.我需要从SharePoint站点获取一些信息.此SharePoint实例是Office 365(即SharePoint Online)的一部分.
我的挑战是,我不能使用帮助库.我必须使用基于REST的API,因为我使用的是.NET Core.
首先,我使用Azure Active Directory注册了我的控制台应用程序.此控制台应用程序是在我的Office 365环境所属的同一Azure Active Directory中创建的.我还将"Office 365 SharePoint Online"API的"读取所有网站集中的项目"权限授予了我的控制台应用程序.
在我的情况下,我有一个控制台应用程序坐在服务器上.我在SharePoint租户上设置了一个用户名/密码的测试用户.我还拥有我在Azure Active Directory中注册的控制台应用程序的客户端ID和重定向URL.
这时,我有一些看起来像这样的代码:
var accessToken = await GetToken(); // retrieves a token from Active Directory
using(var client = new HttpClient()) {
client
.DefaultRequestHeaders
.Clear();
client
.DefaultRequestHeaders
.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
client
.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var apiUrl = "https://[mySite].sharepoint.com/_api/web";
// how do I get the title of the site at the apiUrl variable?
}
Run Code Online (Sandbox Code Playgroud)
因为我正在获取访问令牌,所以我觉得我很接近.我似乎无法弄清楚如何获得该网站的标题.如何从C#代码中获取SharePoint站点的标题?
My application sends email using Microsoft Graph. We followed the documentation, this was working as expected for almost a year:
https://graph.microsoft.com/v1.0/users/me/microsoft.graph.sendmail
Run Code Online (Sandbox Code Playgroud)
Since 3/8/2019, the same code sendmail API in PROD started failing with the HTTP 400 - Bad Request:
{
"error": {
"code": "TargetIdShouldNotBeMeOrWhitespace",
"message": "Id is malformed.",
"innerError": {
"request-id": "0de5a4eb-dac4-4d98-a4b4-178e503a6657",
"date": "2019-03-19T17:16:20"
}
}
}
Run Code Online (Sandbox Code Playgroud)
As a part of the investigation, we found that the SendMail documentation has a different URL used in the examples than …
我正在使用MSAL并且有一位用户收到以下错误:
{
"error":{
"code":"ResourceNotFound",
"message":"Resource could not be discovered.",
"innerError":{
"request-id":"99b44a33-e5cd-4b69-9730-32d72e1f4ebf",
"date":"2016-12-11T03:51:37"
}
}
}
Run Code Online (Sandbox Code Playgroud)
代码是默认的MSAL演示代码:
public async Task<ActionResult> ReadMail()
{
try
{
string signedInUserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
ConfidentialClientApplication cca = new ConfidentialClientApplication(clientId, null,
new ClientCredential(appKey), new MSALSessionCache(signedInUserID, this.HttpContext));
string[] scopes = { "Mail.Read" };
AuthenticationResult result = await cca.AcquireTokenSilentAsync(scopes);
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", result.Token);
HttpResponseMessage hrm = await hc.GetAsync("https://graph.microsoft.com/v1.0/me/messages");
string rez = await hrm.Content.ReadAsStringAsync();
ViewBag.Message = rez;
return View();
}
catch (MsalSilentTokenAcquisitionException)
{
ViewBag.Relogin = …Run Code Online (Sandbox Code Playgroud) 更新:我收到微软的通知,这个问题是Graph API中的一个错误.他们正在研究解决方案.
我正在使用新的v2.0 OAuth流来验证我的应用程序,以便与Microsoft Graph一起使用,以便能够列出任何用户文件,下载和上传任何用户的文件OneDrive并设置文件权限.这没有用户登录,即将其作为服务帐户/守护程序运行.
我在新的应用程序注册门户中设置了一个新的"融合应用程序".我已经设置了所有必要的范围/应用程序权限,包括Files.ReadWrite.All.(我实际检查了所有可能的盒子......).在Microsoft Graph文档中,这应该是调用我感兴趣的端点时唯一必需的范围:
/v1.0/users/{userID}/drive
/v1.0/users/{userID}/drive/items/{ItemID}/children
/v1.0/users/{userID}/drive/items/{ItemID}/content
/v1.0/users/{userID}/drive/items/{ItemID}/invite
/v1.0/users/{userID}/drive/items/{ItemID}/createLink
Run Code Online (Sandbox Code Playgroud)
然后,我按照客户端凭据流程的文档进行操作,包括向应用程序提供管理员同意,以便在我的公司租户中使用.
我成功收到了访问令牌.收到访问令牌后,我在jwt.io上仔细检查过令牌实际上是否包含所有范围(包括Files.ReadWrite.All).
我可以使用此访问令牌获取任何用户的驱动器并列出任何用户文件(上面列出的前两个端点).我也尝试获取任何用户文件的缩略图,它们工作正常.但是一旦我尝试下载文件,添加文件权限或创建共享链接(上面列出的最后三个端点),我就会收到401 Unauthorized错误.由此,我假设范围Files.Read.All工作正常,但范围Files.ReadWrite.All不起作用.
至于我从Scopes文档中可以理解的内容,我尝试使用的范围应该可行.它是"仅限应用程序的权限,需要管理员同意"部分,它描述Files.ReadWrite.All为:
允许该应用在没有登录用户的情况下读取,创建,更新和删除所有网站集中的所有文件.
我撞墙了.新版v2.0 OAuth令牌和/或Microsoft Graph是否存在限制,因为我缺少仅限App的访问权限?
我已将Web应用程序配置为使用Azure Auth登录.一切正常,用户可以登录,如果他们尚未登录到Azure.
我的问题是,当用户已登录到Office 365的Azure并且他们浏览到我的网站时,他们会在下面收到此错误.我理解错误的含义,但我想知道如果出现此问题,是否有办法重定向到另一个URL(在我的网站上).这是错误:

这是我配置OpenId Auth的启动代码:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions {
ClientId = Configuration.clientID,
Authority = authenticationAuthority,
PostLogoutRedirectUri = Configuration.logoutRedirectURL,
Notifications = new OpenIdConnectAuthenticationNotifications {
AuthenticationFailed = context => {
context.HandleResponse();
context.Response.Redirect("/Unauthorised.aspx?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
Run Code Online (Sandbox Code Playgroud) 我一直在尝试在我的.Net Core项目中设置React,并且在尝试运行WebPack时遇到构建失败错误.
我尝试过更新ts-loader和webpack版本,并尝试从GitHub和StackOverflow不同的解决方案,但这些都不起作用.
Webpack控制台错误
Entrypoint global = home-bundle.js home-bundle.js.map
[0] ./ClientApp/Home/home.tsx 289 bytes {0} [built] [failed] [1 error]
WARNING in configuration
The 'mode' option has not been set.
Set 'mode' option to 'development' or 'production' to enable defaults for this environment.
ERROR in ./ClientApp/Home/home.tsx
Module build failed: TypeError: Cannot read property 'ts' of undefined
at getLoaderOptions (D:\MyFirstProject\Travel\node_modules\ts-loader\dist\index.js:70:44)
at Object.loader (D:\MyFirstProject\Travel\node_modules\ts-loader\dist\index.js:23:19)
Run Code Online (Sandbox Code Playgroud)
webpack.config
module.exports = [
{
entry: {
global: "./ClientApp/Home/home.tsx"
},
output: {
filename: "home-bundle.js",
path: __dirname …Run Code Online (Sandbox Code Playgroud) 我想将用户添加到组中,但我没有用户的id,我只有电子邮件地址。
这是代码:
User userToAdd = await graphClient
.Users["objectID"]
.Request()
.GetAsync();
await graphClient
.Groups["groupObjectID"]
.Members
.References
.Request()
.AddAsync(userToAdd);
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我如何使用 Microsoft Graph 从电子邮件地址检索 ObjectId(用户 ID)?
遗憾的是,Office API的某些功能在所有环境中的行为都不完全相同(例如:Excel Online和Excel 2013中的格式化).此外,Excel 2013中没有一些不错的新功能,但在Excel 2016中可用(Excel.js)
当然,我可以告诉用户他们只能在2016年使用我的应用程序,而不是实现在所有环境中都不完全支持的东西.
我更愿意向Excel 2013的用户提供我的应用程序,即使他们没有办法(或倾向于)升级到2016年.我宁愿优雅地降级我的功能列表在功能较少的环境中,而不是将应用程序的功能限制为整个)
它很容易封装与文档的所有交互,并根据环境运行不同的代码.也就是说,如果我知道我所处的确切环境.当前的office.js是否提供了一种发现主机应用程序的版本和上下文(在线/离线)的简洁方法?我在office.context等等找不到任何东西.
在网上有一些关于黑客攻击整个.getContext链条的建议,但这些似乎是"无证件"的,所以我对此并不满意.
有什么建议?