Contrary to the documentation on https://learn.microsoft.com/en-us/graph/api/profilephoto-update?view=graph-rest-1.0&tabs=http there is no .Content object available under .Photo.
group.Photo.Content.Request().PutAsync(photoStream).Result;
I am looking to update the profile photo for the group and it does not seam to be available.
Below code is working for me. Can you please try similar way.
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var stream = await graphClient.Groups["groupId"].Photo.Content
.Request()
.GetAsync();
I have installed Microsoft.Graph Nuget version 3.4.0.
Related
I need to update RestSharp to newest version in one project and once the newest version is installed and referenced, an existing RestRequest call causes error.
Uri uri = new Uri(url);
var client = new RestClient(uri.Scheme + "://" + uri.DnsSafeHost);
client.Authenticator = new HttpBasicAuthenticator(username, password);
var RSrequest = new RestRequest(uri.AbsolutePath, Method.POST);
What Visual Studio complains about is "Method.POST" instead of "Method.Post". Once updated to "Method.Post", project builds fine but the RestRequest call does not seem work as intended. When I look into RestRequest definition with RestSharp updated to newest version, it looks different than the old version, as it defaults to Method.Get:
public RestRequest(string? resource, Method method = Method.Get)
How can this be fixed? Obviously, I do not have much RestSharp knowledge, neighter I am the author of the code I am about to update.
Tried this:
graphServiceClient
.sites(siteId)
.pages(pageId)
.buildRequest()
.get() but seems earlier pages method was supported and now it's not appearing.
Is there any way to get site page collection?
thanks for reaching out ,I understood that you are trying to get list of sites, looks like you are using async await ,please convert your get() function to GetAync() and add await.
Could you please try by using the below sample code
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var items = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items .Request()
.GetAsync();
ref docs - https://learn.microsoft.com/en-us/graph/api/listitem-list?view=graph-rest-1.0&tabs=csharp#request
Hope this helps , please let us know if you have any query
thanks
In my C# application I am trying to search for a User via Graph API. The only parameter I have is the username which is stored in onPremisesSamAccountName field.
Through Graph Explorer I can successfully run the query
https://graph.microsoft.com/v1.0/users?$count=true&$search="onPremisesSamAccountName:myusername"&$select=id,displayName
And Graph Explorer gives me the C# code to use
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var users = await graphClient.Users
.Request()
.Search("onPremisesSamAccountName:myusername")
.Select("id,displayName")
.GetAsync();
Now when I try to use that code I get an error saying that Search is not a method, do I need to add an extra package to use Search?
I also didn't find any nuget package with Search method.
You can specify search value by using query option. $search query parameter requires a request header ConsistencyLevel: eventual
var queryOptions = new List<Option>()
{
new QueryOption("$search", "\"onPremisesSamAccountName:myusername\""),
new HeaderOption("ConsistencyLevel", "eventual")
};
var users = await graphClient.Users
.Request(queryOptions)
.Select("id,displayName")
.GetAsync();
Your c# example for https://graph.microsoft.com/v1.0/me/people?$search="jesper"
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var people = await graphClient.Me.People
.Request()
.Search("jesper")
.GetAsync();
Error I'm getting:
not sure if this is meant to happen but seems wrong that you cant use the search function
https://developer.microsoft.com/en-us/graph/graph-explorer
Yes, you're absolutely right. Those snippets are generated by a tool, and sometimes it gets it wrong. Thanks for reporting!
You can add any query parameters to requests sent by the SDK though, so you can still make this work like so:
var options = new List<QueryOption> { new QueryOption("$search", "j") };
var people = await graphClient.Me.People.Request(options).GetAsync();
Trying to access discovery client for acceising other endpoints anf following with,
http://docs.identityserver.io/en/aspnetcore1/endpoints/discovery.html
Installed IdentityModel nuget package in .Net 7.5 MVC application. But unable to find the DiscoveryClient.
var discoveryClient = new DiscoveryClient("https://demo.identityserver.io");
var doc = await discoveryClient.GetAsync();
Is there something change in Identitymodel for IdentityServer4
Also, unable to find parameter for "Tokenclient".
Able to figure out, change in IdentityModel, its all extension of HttpClient.
https://identitymodel.readthedocs.io/en/latest/client/discovery.html
var client = new HttpClient();
var disco = await client.GetDiscoveryDocumentAsync("https://demo.identityserver.io");
Yes, you are correct. There are lot of changes in the IdentityModel NuGet package.
Below code will help you:
HttpClient httpClient = new HttpClient();
//Below code will give you discovery document response previously we were creating using DiscoveryClient()
// They have created `.GetDiscoveryDocumentAsync()` extension method to get discovery document.
DiscoveryDocumentResponse discoveryDocument = await httpClient.GetDiscoveryDocumentAsync();
// To create a token you can use one of the following methods, which totally depends upon which grant type you are using for token generation.
Task<TokenResponse> RequestAuthorizationCodeTokenAsync(AuthorizationCodeTokenRequest)
Task<TokenResponse> RequestClientCredentialsTokenAsync(ClientCredentialsTokenRequest)
Task<TokenResponse> RequestDeviceTokenAsync(DeviceTokenRequest)
Task<TokenResponse> RequestPasswordTokenAsync(PasswordTokenRequest)
Task<TokenResponse> RequestRefreshTokenAsync(RefreshTokenRequest)
Task<TokenResponse> RequestTokenAsync(TokenRequest)
For example if you want to create a token for password grant type then use below code:
PasswordTokenRequest passwordTokenRequest = new PasswordTokenRequest()
{
Address = discoveryDocument.TokenEndpoint,
ClientId = ClientName,
ClientSecret = ClientSecret,
GrantType = GrantTypes.ResourceOwnerPassword,
Scope = scope,
UserName = userName,
Password = password
};
httpClient.RequestPasswordTokenAsync(passwordTokenRequest);
I hope this will help you!
If you used some sample code and the other answers aren't working, because HttpClient doesn't have GetDiscoveryDocumentAsync
var client = new HttpClient();
var disco = await client.GetDiscoveryDocumentAsync("https://localhost:5001");
Update your IdentityModel package, in Visual Studio:
Right click Dependencies -> Manage Nuget Packages -> Updates (select "All" in top right corner)