Reputation: 894
I have Skype web API which can be called and used inside javascript. Now, I have created a simple C#.Net console application and want to use the API.
So, Does c# has any API using which we can run javascript and get the output in json or xml or any other standard format.
Thanks in advance.
Upvotes: 0
Views: 392
Reputation: 12805
You don't need to run Javascript inside your C# code. .NET has its own set of functionality to get the information.
The System.Net.WebClient class has a .DownloadString()
method that you can use to get the same information from the Skype API as you would in your JavaScript code.
Take that string that you receive from there and use Newtonsoft's JSON DLL (available through NuGet) to turn that string into a JSON object that you can get all of the information from.
Here is an example of the code that I used to do this in one of my projects, modified for generality. For reference, the DLL's you'll need to add using
s for are System.Net
, and Newtonsoft.Json.Linq
.
private static GetData(string urlParameter) {
string response = string.Empty; // This will be the data that is returned.
string url = "http://skype.api.com/someCall?param={0}"; // The API URL you want to call.
using (var client = new WebClient()) {
// This will get the data from your API call.
response = client.DownloadString(string.Format(url, urlParameter));
}
JObject obj = null; // This is the Newtonsoft object.
try {
obj = JObject.Parse(response);
// Continue on processing the data as need be.
}
catch {
// Always be prepared for exceptions
}
Upvotes: 2
Reputation: 254
The API you are attempting to call is used by the client through their web browser. It makes no sense to attempt to integrate with it using C# on the server side; it'll never work because it won't be able to talk to Skype running on the user's computer. If you're writing a web app in C# then you need to make the Skype API calls in client-side JS running in the user's browser. If you're not writing a web app then I have no idea what you're trying to accomplish, but it's not going to work.
Upvotes: 0