Azure Resource Manager - Get all the resources of a resource group - c#

Yesterday, I was using this line of code with the version 1.5.0-preview of Microsoft.Azure.Management.ResourceManager :
var listResources =
ResourceManagementClient.ResourceGroups.ListResources(resourceGroup.Name);
Today, I have updated to version 1.6.0-preview but the fonction doesn't seem to be available anymore. Is there another way to get the list of the resources contained in a resource group ?

Now the SDK is still preview version. In the 1.6.0 preview version. It should use following code.
var listResources = resourceManagementClient.Resources.ListByResourceGroup("ResourceGroup Name");
But it still can't work correctly on my side because the API-Version is api-version=2017-05-10. I catch the request with fiddler.
The code you mentioned that use API-version
var listResources =
ResourceManagementClient.ResourceGroups.ListResources(resourceGroup.Name);
Note : Please still use 1.5.0-preview instead of 1.6.0-preview currently if you want get group resource, or give your feedback to azure sdk team . Or you can use REST API directly

Related

Azure VisualSearch fails with Unauthorized despite valid key

I feel I must be missing something obvious here. I've been trying to follow the instructions at https://learn.microsoft.com/en-us/bing/search-apis/bing-visual-search/quickstarts/sdk/visual-search-client-library-csharp. I created a "Bing Search" service in Azure with the S9 tier which supports Visual Search. I went to the Keys and Endpoint section and copied the Key 1 out and put it in the below code, yet every time I run it I get Unauthorized:
{"code":"401","message": "Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}
var client = new VisualSearchClient(new Microsoft.Azure.CognitiveServices.Search.VisualSearch.ApiKeyServiceClientCredentials("<key>"));
ImageInfo ImageInfo = new ImageInfo(url: "https://media.vanityfair.com/photos/5d9f5be40fa2040008f28470/4:3/w_1776,h_1332,c_limit/always-sunny-in-philadelphia-hangs-in-there.jpg");
VisualSearchRequest VisualSearchRequest = new VisualSearchRequest(imageInfo: ImageInfo);
var result = await client.Images.VisualSearchMethodAsync(knowledgeRequest: JsonConvert.SerializeObject(VisualSearchRequest));
The instructions don't say anything about setting an endpoint, but I tried that too, setting the Endpoint property from the one in my Keys and Endpoint page:
client.Endpoint = "https://api.bing.microsoft.com/";
But that just result in a NotFound error.
Anyone have any idea what's going on? I tried both keys with no success. Here's a LINQPad repro of the issue: http://share.linqpad.net/c3p8vo.linq
Thanks!
I figured out the issue. The documentation is actually wrong (as of 8/9/22). It says
The NuGet Visual Search package.
From the Solution Explorer in Visual Studio, right-click on your project and select Manage NuGet Packages from the menu. Install the Microsoft.Azure.CognitiveServices.Search.VisualSearch package.
But that's the old nuget package, which has the old endpoint in it: https://api.cognitive.microsoft.com. The new endpoint is https://api.bing.microsoft.com. I found that there's actually another, newer nuget package, Microsoft.Bing.Search.VisualSearch which has the correct endpoint, but I can't find documentation anywhere pointing to it!
Once I switched to that nuget package though, everything worked as expected when passing an imageUrl. I still can't get it to work with a FileStream though, I think that might be broken as well.

Microsoft Graph Client SDK vs. Requesting JSONs

I know that the query:
https://graph.microsoft.com/v1.0/me/messages
Corresponds to:
GraphClient.Me.Messages.Request().GetAsync()
I am trying to replicate the following requests in Microsoft Graph Client SDK :
Get All Categories
https://graph.microsoft.com/beta/me/outlook/masterCategories
Corresponding Graph client query: ??
Get All messages that contain certain words in their subject
The link will be similar to this
https://graph.microsoft.com/v1.0/me/messages?$search="hello world"
Corresponding Graph Client : ??
Update each of these messages with a category
?
The documentation only gives 2 examples, where could i find a list of examples/reading material on this?
The SDK is generated for the production endpoint (v1.0), so you will have to make a custom request for beta APIs
List<QueryOption> options = new List<QueryOption>
{
new QueryOption("$search", "hello world")
};
var filteredMessages = await
graphClient.Me.Messages.Request(options).GetAsync();
This also requires using custom requests since this is beta functionality.
We appreciate your feedback about our docs and how to use the SDK. We have some additional reference in the repo and are continuing to examine options for improving our SDK docs.
Since I don't have enough reputation points, I had to post an answer instead of a comment.
Thanks user8608110 for your help. Unfortunately, I can't use graph explorer because I'm not an admin. I think I have my patch request setup correctly, but I keep getting an "Empty Payload" error.
I thought stackoverflow was for us to help each other not delete the post of people trying to get help.

Google Datastore authentication issue - C#

I'm trying to connect to the Google Datastore on my account with service account credentials file (which I've created according to the documentation), but I'm encountering with authentication error while trying to insert an entity:
Grpc.Core.RpcException: Status(StatusCode=Unauthenticated,
Detail="Exception occured in metadata credentials plugin.")
My code is:
var db = DatastoreDb.Create("myprojectid");
Entity entity = new Entity{
Key = db.CreateKeyFactory("mykindname").CreateIncompleteKey()
};
var keys = await db.InsertAsync(new[] { entity });
The GOOGLE_APPLICATION_CREDENTIALS variable refers to the credentials file and when calling GoogleCredential.GetApplicationDefaultAsync() to see if the credentials object is valid it indeed looks good...
I saw some earlier examples which used the GetApplicationDefaultAsync function togehether with some DatastoreService object - but I couldn't find the DatastoreService object (probably it was there in old versions...) in the latest .Net API: Google.Cloud.Datastore.V1
Notice that I don't want to use the other authenticaiton methods:
1) Using the gcloud cli.
2) Running from Google environment (app engine for example).
Any idea how to solve this?
After the great help of Jon Skeet the issue was solved.
The authentication issues can occur if you don't reference all the required Datastore dlls. Make sure that all the dlls are referenced on the project that are running the calls to the Datastore.
I've added the Google Datastore lib via the NuGet to my test project and everything worked!
Notice that in such cases it is recommended to enable gRPC logging. `(For exmaple: GrpcEnvironment.SetLogger(new ConsoleLogger()), there you'll probably see if there were issues loading several dlls...
Authentication can be broken if your system clock is significantly incorrect. Check your system time, and fix it if necessary, then try authenticating against Datastore again.

Trello C# api, .Boards.WithId() and .Members.Me() are always null [duplicate]

I am new to Trello.Net and struggling a little with authorisation. I understand the process, of requesting a URL and then asking the user to browse to that URL to get a token.
The first problem is I am trying to write a process which runs automatically without any UI. So I'm having to use a hard coded token, which I obtained by running this code to get a URL, which I then browse to manually. I would rather do this part automatically (get the resulting token programatically, not by having the user browse somewhere):
ITrello trello = new Trello(Key);
var url = trello.GetAuthorizationUrl("TrelloCapture", Scope.ReadWrite, Expiration.Never);
Console.WriteLine(url);
This URL, when I browse to it, displays for me a token which, for now, I hardcoded into my application as follows:
var token = "[the token copied and pasted from the web page]"
I then authorise using:
trello.Authorize(token);
Which seems to work fine. Next I want to access some basic data, and this is where my second problem comes in.
// Get the authenticated member
Member me = trello.Members.Me();
Console.WriteLine(me.FullName);
Members.Me() returns null every time. The same problem with Cards.ForMe() and other methods. Everything is null. Why?
What am I doing wrong?
I found the answer. I fixed it by getting the latest versions of these NuGet packages in my solution:
Trello.Net
JSON.Net
RestSharp
After getting those latest versions I was seeing proper values instead of null in the trello objects.
Hope this helps somebody who reads this.
Had the same problem, above answer helped me.
Though I couldn't get the latest but had to use:
"RestSharp" version="104.1
"Newtonsoft.Json" version="6.0.1"
Since The nuget also doesn't have the correct color enum i had to download the project and make my own changes.

Retrieve note SourceUrl through ENNoteAdvanced

I would like to retrieve the URL associated with (some) Evernote notes, as seen in this screenshot:
Need for ENNoteAdvanced
After some digging, I found that the object ENNoteAdvanced has a property SourceUrl that should be exactly what I need.
However, I cannot find a way to download or cast an existing note as ENNoteAdvanced
Code for retrieving ENNote but how about ENNoteAdvanced
ENNote downloadedNote = sharedSession.DownloadNote(noteRef);
I fear the API only allows creating new advanced notes for uploading, but does not allow working with existing downloaded notes as advanced notes?
You are correct, that was a shortcoming of the new Evernote Windows SDK. So I just modified the SDK so as to support calling DownloadNote from the Advanced interface, which will return an ENNoteAdvanced instead of an ENNote.
In other words, do this:
ENSessionAdvanced.SetSharedSessionConsumerKey("your key", "your secret");
...[your code which authenticates, then gets you a valid noteRef]...
ENNoteAdvanced downloadedNote = ENSessionAdvanced.SharedSession.DownloadNote(noteRef);
Console.WriteLine(downloadedNote.SourceUrl);
The updated SDK is available on Github now.

Categories