Nuget api issue - c#

I need to automatically collect the information from the nuget packages of a series of projects. For this purpose I use the API that miscrosoft makes available.
Making the call:
https://api.nuget.org/v3/registration3/epplus/index.json
I get the most recent version: v.4.5.3.1 while on the nuget website it is: v. 5.1.2.
To make the call I use the following code:
static void GetNuGetIndex(Model.Package package)
{
string uri = "https://api.nuget.org/v3/registration3/" + package.Name.ToLower() + "/index.json";
string json = new WebClient().DownloadString(uri);
var packageIndex = JsonConvert.DeserializeObject<JSONModel.NuGetPackageIndex>(json);
int packageIndexItemCounter = 0;
if (packageIndex.Items.Count > 0)
foreach (var packageItem in packageIndex.Items)
{
packageIndexItemCounter++;
List<JSONModel.NuGetPackageItem> items = packageItem.Items;
if (packageItem.Items == null)
{
string lookupjson = new WebClient().DownloadString(packageItem.LookupUrl);
items = JsonConvert.DeserializeObject<JSONModel.NuGetPackageItems>(lookupjson).Items;
}
GetNuGetItems(package, items, package.Name, package.Version, (packageIndexItemCounter.Equals(packageIndex.Items.Count) ? packageItem.Upper : "" ));
}
}
Can anyone give me an explanation of why I have this problem and how can it be solved?
Thanks

I believe this is because this endpoint has been discontinued.
Consulting to the service index api, available at: https://api.nuget.org/v3/index.json (DOC) you can see that the address you are using is not returned.
When consulting the endpoint https://api.nuget.org/v3/registration5-semver1/epplus/index.json provided by the index api, the "upper" field will now return the most current version

I looked here, which suggests you need a different query to return packages:
https://api.nuget.org/v3/registration5-semver1/epplus/index.json

As Kelvin mentioned, that registration hive has been discontinued. I would recommend using the NuGet client SDK to interact with the NuGet API: https://learn.microsoft.com/en-us/nuget/reference/nuget-client-sdk#list-package-versions
If you still would like to use the NuGet APIs directly, I recommend reading through the following resources:
https://learn.microsoft.com/en-us/nuget/api/overview
https://learn.microsoft.com/en-us/nuget/api/service-index
https://learn.microsoft.com/en-us/nuget/api/registration-base-url-resource
TLDR: You have to "discover" the latest location of the registration endpoint using the V3 Service Index API at https://api.nuget.org/v3/index.json.

Related

APIM endpoint is not working through latest elastic client library

I am using latest "Elastic.Clients.Elasticsearch" library in .NET console application to talk to my elastic latest version 8.X. However, in my scenario I will not be talking directly to elastic I have a middle layer APIM endpoint. This is working fine when I am using NEST package with EnableAPIVersioningHeader setting. But in case of new library it throws 404 "resource not found error". Please can you let me know what are the changes that needs to be done to get this working.
Note: I am removing NEST package dependency from code, as Elastic will not support it in the future.
Sample Code:
public static ElasticsearchClient NewSearchClusterClient
{
get
{
var connectionSettings = new ElasticsearchClientSettings(new Uri("<apimendpoint>"));
connectionSettings.MaximumRetries(5);
connectionSettings.DefaultIndex("test");
connectionSettings.IncludeServerStackTraceOnError(true);
connectionSettings.EnableTcpStats(true);
connectionSettings.DisableDirectStreaming(true);
NameValueCollection collection = new NameValueCollection
{
};
connectionSettings.GlobalHeaders(collection);
var client = new ElasticsearchClient(connectionSettings);
return client;
}
}
Call this --> var respone = NewSearchClusterClient.Search(q => q.Query(m => m.MatchAll()));

Retrieving Profiles and connections - Parameter missing?

I use Google's .NET people API (v.1.25) and follow the documentation (https://developers.google.com/people/v1/read-people).
Under
Retrieve Profiles and Connections
Get the user's connections
for .NET the documentation gives this example code snippet:
PeopleResource.ConnectionsResource.ListRequest peopleRequest =
peopleService.People.Connections.List("people/me");
peopleRequest.PersonFields = "names,emailAddresses";
ListConnectionsResponse connectionsResponse = peopleRequest.Execute();
IList<Person> connections = connectionsResponse.Connections;
But PersonFields do not exist in the class ListRequest - nor does it exist in GetRequest as the doc suggests in the next example.
Do I misunderstand something or is there a fault in the docs or in the API?
It seems like you are using an old version of the library. If you browse the .NET documentation from the Install Client Libraries page it shows the version is 1.5.1.
If you browse to the ConnectionsResource.ListRequest documentation it shows that PersonFields exists.
Just use .Fields instead of .PersonFields. Also I had to declare the entire package name (Google.Apis.People.v1.). Example below.
Google.Apis.People.v1.People.PeopleService peopleService;
Google.Apis.People.v1.PeopleResource.ConnectionsResource.ListRequest peopleRequest = peopleService.People.Connections.List("people/me");
peopleRequest.Fields = "names,emailAddresses";
ListConnectionsResponse connectionsResponse = peopleRequest.Execute();
IList<Google.Apis.People.v1.Data.Person> connections = connectionsResponse.Connections;
Hope this helps.

Google cloud translator .net client

I am trying to use google translator api in my .net project. I have installed this library
Install-Package Google.Cloud.Storage.V1
In my code I am trying this
Console.OutputEncoding = System.Text.Encoding.Unicode;
TranslationClient client = TranslationClient.Create();
var response = client.TranslateText("Hello World.", "ru");
Console.WriteLine(response.TranslatedText);
I am getting authentication error, I am really confused how to do that. Can't I just pass an api key into the create function as it is? Or is that an issue?
I see that Create function has an option
GoogleCredential.FromJson(parmas)
But can I pass a json string as it in there? And if yes, what should be the format of that JSON?
Thanks in advance.
Here are sample applications:
https://github.com/GoogleCloudPlatform/dotnet-docs-samples
Authentication info:
https://cloud.google.com/docs/authentication/
https://cloud.google.com/docs/authentication/api-keys
First install NuGet package:
PM> install-package Google.Cloud.Translation.V2 -pre
Here is the absolute simplest code that worked for me.
3 lines of code, not bad :)
var service = new TranslateService(new BaseClientService.Initializer { ApiKey = apiKeyTranslate });
var client = new TranslationClientImpl(service, TranslationModel.ServiceDefault);
var result = client.TranslateText("Hello, World", "sr");
Response.Write(result.TranslatedText);
Refer this link - https://developers.google.com/identity/protocols/application-default-credentials. Download .json file.
Install Google.Cloud.Translation.V2
string credential_path = #"D:\..\..\cred.json";
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);

Is there a more efficient way to deal with Amazon Product advertising API on C# ASP.NET (esp MVC 5)?

I have finally got the Amazon product advertising API to work on my MVC 5 site. I am using the "SignedRequestHelper" class that was provided on one of the downloads from the Amazon site. I have actually got a ref to the Amazon API but I do not seem to be using it at all at present.
What I am using so far is (controller):
SignedRequestHelper helper = new SignedRequestHelper("myAWSaccessKeyID",
"mysecretKey", "webservices.amazon.co.uk");
Dictionary<String, String> items = new Dictionary<String, String>();
items.Add("Service", "AWSECommerceService");
items.Add("Operation", "ItemSearch");
items.Add("AWSAccessKeyId", "myAWSaccessKeyID");
items.Add("AssociateTag", "myTag");
items.Add("SearchIndex", SearchIndex);//This is a string value (selectbox)
items.Add("ResponseGroup", "Images,ItemAttributes,OfferFull,Offers,OfferSummary,Reviews");
items.Add("Keywords", keyword);//This is a string value
string requestUrl = helper.Sign(items);
ViewBag.Stuff = requestUrl;//Just so I could see the whole URL!
WebRequest request = HttpWebRequest.Create(requestUrl);
WebResponse response = request.GetResponse();
XmlDocument doc = new XmlDocument();
doc.Load(response.GetResponseStream());
XmlNodeList titleNodes = doc.GetElementsByTagName("Item");
ViewBag.Titles = titleNodes;
You may notice I partially the copied the style of JAVA code from the scratch pad.
From that point on in the view I just deal with each part as it comes. It is kind of messy and horrid and dealing with switches like this:
foreach (System.Xml.XmlNode item in ViewBag.Titles)
{
<h3>Item: #count</h3>
foreach (System.Xml.XmlNode child in item.ChildNodes)
{
switch (child.Name)
{
case "ASIN":
<p>ASIN: #child.InnerText</p>
break;
case "MediumImage":
<img src="#child.ChildNodes[0].InnerText" />
break;
case "ItemAttributes":
foreach (System.Xml.XmlNode child1 in child.ChildNodes)
{
if(child1.Name == "Title")
{
<p>#child1.InnerText</p>
}
}
break;
}
}
count++;
}
It works and I can use the XML document etc. I just need to know if there is a way to change it so that it is actually using the API part that was given as a reference. I would rather use proper tools than do it with raw XML like this. I had such difficulty connecting with the Amazon documentation that I basically just tried to connect in the JAVA style code on Amazon's scratchpad.
You can use the following nuget Nager.AmazonProductAdvertising package.
PM> Install-Package Nager.AmazonProductAdvertising
Example Controller
public ActionResult ProductSearch(string search)
{
var authentication = new AmazonAuthentication();
authentication.AccessKey = "accesskey";
authentication.SecretKey = "secretkey";
var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
var result = wrapper.Search(search);
return View(result);
}
Example View
#model Nager.AmazonProductAdvertising.Model.AmazonItemResponse
#{
ViewBag.Title = "Search";
}
<table class="table">
<tr>
<th>ASIN</th>
<th>SalesRank</th>
</tr>
#foreach (var item in Model.Items.Item)
{
<tr>
<td>#item.ASIN</td>
<td>#item.SalesRank</td>
</tr>
}
</table>
Take a look to AWS SDK for .Net. Also you can find some guides and how to work with it's APIs.
The AWS SDK for .NET includes the following:
The current version of the AWS SDK for .NET.
All previous major versions of the AWS SDK for .NET.
Sample code that demonstrates how to use the AWS SDK for .NET with several AWS services.
There is a library that is incredibly thorough for dealing with the Amazon Product Advertising API (PAAPI). When you make a request, you can receive a variety of responses, but this library can handle them all! It reads the XML and puts all the information in an object.
I'm working on two MVC 5 sites right now that interact with the PAAPI. I have a separate folder with the files and a couple files I wrote to make requests and process responses by pulling the data I need out of the object created by the library.
I made a C# console app demo, and you can view it here:
https://github.com/zoenberger/AmazonProductAdvertising
I used this for guidance:
https://flyingpies.wordpress.com/2009/08/01/17/
However, I ran into a couple errors:
In some instances, large responses require you to modify the
MaxReceivedMessageSize and is show on the demo.
I ran into an error with the ImageSets[] in the library. May people have and the fix is here.
I believe that I have finally found a way to use the actual Amazon Prod Adv API now. The problem was working out how to sign the request using the latest API (that I had added as a reference). The reference was added in a similar way to the getting started guide even though that was making reference to VS2005. That is obviously 10 years old but I somehow did get it working with a bit of problem solving. I just never got the signing correct so I ended up using that horrid REST bodge (in my original question)!
The post that has helped me now is this one:
amazon product advertising api - item lookup request working example
It is the one marked as the answer. It has only 4 up-votes but it is the best thing I have found. I put all the classes into the controller to test it but I will now have to do it properly using models or extension classes. It worked anyway though.

Twilio Test Credentials: WaitingForActivation when I try to purchase a number?

I have the following code:
public void PurchaseNumber(string username, string phoneNumber) {
var twilio = new TwilioRestClient(accountSid, authToken);
var options = new PhoneNumberOptions {
VoiceUrl = "",
PhoneNumber = "+15005550006"
};
var number = twilio.AddIncomingPhoneNumber(options);
Console.WriteLine(number.Id); // Sid is not available
return;
}
Two issues - number.Sid is not available, as the samples display, and number.Status always shows "WaitingForActivation". What am I doing wrong?
Update: This also happens with the 'unavailable' number, not just with the 'valid and available' one. Is the usage of magic numbers available to trial accounts? I am using the SID and Token from the https://www.twilio.com/user/account/developer-tools/test-credentials page.
This also happens if I change one of the characters of my SID - so it seems that my SID is invalid, despite grabbing it directly off of my /developer-tools page.
Final Update - it was because I was using the PreRelease version of the Twilio nuget package. I uninstalled it and installed the non-prerelease version and Sid became available and everything started working.
Final Update - it was because I was using the PreRelease version of the Twilio nuget package. I uninstalled it and installed the non-prerelease version and Sid became available and everything started working.

Categories