Ich experimentiere mit der Microsoft Graph-API und richte ein Projekt mit den QuickStarts auf der Microsoft-Entwickler-Website ein.Wie listet man alle Kontakte mit Microsoft Graph auf?
Ich habe derzeit Probleme, wenn ich alle E-Mail-Kontakte auflisten möchte, die dem angemeldeten Konto zugeordnet sind.
Mein Problem scheint zu liegen, wie ich Anfrage und Weitergabe der Informationen an ViewBag
, da es eine NullReference
Ausnahmen sogar mit der richtigen Front-End-Auflistung wirft.
ist hier der entsprechende Code:
HomeController.cs
public async Task<ActionResult> GetMyContacts()
{
try
{
// Init GraphServiceClient
GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
var contacts = await graphService.GetMyEmailContacts(graphClient);
ViewBag.Contacts = contacts;
return View("Graph");
}
catch (ServiceException se)
{
if (se.Error.Message == Resource.Error_AuthChallengeNeeded) return new EmptyResult();
return RedirectToAction("Index", "Error", new { message = Resource.Error_Message + Request.RawUrl + ": " + se.Error.Message });
}
}
GraphService.cs
public async Task<IList<Contact>> GetMyEmailContacts(GraphServiceClient graphClient)
{
User me = await graphClient.Me.Request().Select("mail,userPrincipalName").GetAsync();
var contacts = me.Contacts;
return contacts;
}
Graph.cshtml
<div class="col-sm-12">
<pre name="user-contacts">@ViewBag.Contacts</pre>
</div>
<h2>TEST GET CONTACTS</h2>
<div class="col-sm-12">
<p>@Html.Raw(ViewBag.Contacts)</p>
</div>
Was ich hier fehlt?
Können Sie bitte Ihre forontend Code für Graphansicht zeigen? – krzysztofla
@KrzysztofLa Erledigt –