I am using SignalR in MVC to display information in a basic chat type device in MVC. This is all working ok but I want to display information from a Json payload that has been deserialized like this:
Dim iss As IssueObjectClass = JsonConvert.DeserializeObject(Of object)(json)
The information does not have to being displayed does not just have to be an object it could be a variable as well, for example I could also display this:
Dim key = iss.issue.key
I have the code for the connection using the chat hub device which is displaying basic information (Message and username). Is this the way that I should try and display my Json using SignalR. I know that SignalR is used for real-time web applications but I am unsure on how it could display information that has been fired from a webhook as a Json payload.
This is how I am displaying the messages in the chat hub, but I want to display information that is coming from a webhook unrelated to anything that has been typed on the application. I want to display information from a HTTP POST from JIRA:
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
$('#discussion').append('<li><strong>' + encodedName + '</strong>: ' + encodedMsg + '</li>');
$('#discussion').text = encodedMsg;
How can I integrate SignalR with Json to display it?
It's a pretty simple thing to do, and a common case with SignalR. In your code where to receive and deserialize your object, you just have to call something like:
var context = GlobalHost.ConnectionManager.GetHubContext<YourHub>();
context.Clients.All.broadcastIssue(iss);
On your client you'll have to define a handler this way before you start the connection:
var yourHubProxy = $.connection.yourHub;
yourHubProxy.client.broadcastIssue = function (iss) {
// ...do your stuff...
};
This is very basic code which would need to be better organized, but it should put you on the right track. My advice is you go through the official SignalR documentation, which is extensive and well done, in particular the guides to the APIs.
Related
So I'm trying to import Cardano Blockchain data like address balance, amount staked, rewards etc into a Google Sheet. I found this project named Blockfrost.io which is an API for accessing Cardano blockchain info and import it into apps etc.
I think I can use this with Google Sheets. Problem is I don't know how to authenticate. I've searched all around on the documentation and it's not clear to me. It seems it's possible if your're building an app or using the terminal.
But I just want to authenticate in the easiest way possible like in the browser address bar that way it would be simple to get the JSON with the info I need and import the info to Google Sheets.
This is where it mentions the Authentication:
https://docs.blockfrost.io/#section/Authentication
I already have an API key to access. But how do I authenticate?
So if I want to check the blockchain metrics (mainnet1234567890 is a dummy key, I won't use mine here):
https://cardano-mainnet.blockfrost.io/api/v0/metrics/project_id:mainnet1234567890
The JSON will still output this:
status_code 403
error "Forbidden"
message "Missing project token. Please include project_id in your request."
Is there a correct way to authenticate on the browser address bar?
It's not clear which BlockFrost API you are using Go JavaScript etc...
the API key goes in as a header on the request object. I was manually trying to connect to the service and found for a request is what I had to do in C#...
var aWR = System.Net.WebRequest.Create(url);
aWR.Method = "GET";
aWR.Headers.Add("project_id", "mainnetTheRestOfMyKeyIsHidden");
var webResponse = aWR.GetResponse();
var webStream = webResponse.GetResponseStream();
var reader = new StreamReader(webStream);
var data = reader.ReadToEnd();
Later I realized I wanted to use their API cause they implement the rate limiter, something I would rather use than build... I use the following with the BlockFrost API in c#
const string apiKey = "mainnetPutYourKeyHere";
const string network = "mainnet";
// your key is set during the construction of the provider.
ServiceProvider provider = new ServiceCollection().AddBlockfrost(network, apiKey).BuildServiceProvider();
// from there individual services are created
var AddressService = provider.GetRequiredService<IAddressesService>();
// The call to get the data looked like
AddressTransactionsContentResponseCollection TXR = await AddressService.GetTransactionsAsync(sAddress, sHeightFrom, sHeightTo, 100, iAddressPage, ESortOrder.Desc, new System.Threading.CancellationToken());
// etc. your gonna need to set the bounds above in terms of block height
Try using postman and include the "project_id" header with api key as the value like this - it will clear up the concept for you I think:enter image description here
I need some help to post username and password to a web page and then invoke the click event for the log in.
In order to better understand what I'm trying to do, a good example could be the following one:
programmatically send to a bank account's web page username and password (in the relevant inputs) and then, once logged in, retrieve the balance.
This means that in my app I'll have a XAML page with 2 textboxes, 1 button and 1 textblock.
Parse a site is quite easy, so that I'd be able to get the balance but I can't send the data to the server for the log in.
I've already read several examples with WP8 but none of them allows me to understand how to proceed with WP8.1 where, apparently, things are little bit different.
I've tried with this code where I assumed the inputs are called "user" and "password":
private async void LogIn_Click(object sender, RoutedEventArgs e)
{
string url = "http://www.something.com";
WebRequest request = WebRequest.Create(url);
string postData = "user=" + textBoxUser.Text + "&password=" + textBoxPassword.Text;
byte[] send = Encoding.UTF8.GetBytes(postData);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
Stream sout = await request.GetRequestStreamAsync();
sout.Write(send, 0, send.Length);
sout.Dispose();
var myHttpClient = new System.Net.Http.HttpClient();
var response = await myHttpClient.GetAsync(url);
var dataBack = await response.Content.ReadAsStringAsync();
//Debug:
Debug.WriteLine(dataBack);
}
Even though I don't receive any error, the inputs in the response are empty and moreover I don't know how to invoke the click event of the button in the web page to submit the data.
In addition, I don't want to open the web page since everything would be managed by the 4 controls of the app.
Is there anybody who can give some suggestion or address me where I can find something which suits my need?
Thanks
Looks like you're already on the right path: putting together the correct POST request the way a browser would send it after the user submits the form.
You may however need to set Referer parameters and maybe a CSRF token or such in addition to naming the parameters correctly. The best approach would be to submit the form in an actual browser and look at the request that it sends via the built-in developer tools, then reverse-engineer that one from within your app.
I'm developing a simple youtube app in adobe air, so far I could get the approval window in youtube and getting the token for uploading. However I'm stuck in the part where you send the data on POST with all the information (https://developers.google.com/youtube/2.0/developers_guide_protocol_direct_uploading)
I already loaded my video data as a bytearray, what I need is to create the whole POST request containing all the information as it shows in the link. (the xml atom feed, the bytearray data, etc.) I have all the information needed, I just need to structure the POST request.
How to do that in as3/air? Do I create all the information as URLVariables? which ones are headers and which ones arent? How do you add the --< boundary_string> to the POST? How do you add the bytearra to the POST? All help is highly appreciated.
Thanks!
I have always done something like this when sending POST variables:
<fx:Declarations>
<s:HTTPService id="loginServ" resultFormat="text" result="onResult(event)" method="POST" url="http://www.myurl.com/login.php"/>
</fx:Declarations>
Then you would have two functions, one for sending the request and one for handling the result you get back:
private function login():void{
//Make a new Object to hold all of your POST variables
var reqInfo:Object = new Object();
//Then set the properties of that Object to be each POST variable
reqInfo.username = "admin";
reqInfo.password = "password";
//Finally, send the request with the Object as the parameter
loginServ.send(reqInfo);
}
private function onResult(e:ResultEvent):void {
trace("Result:" + e.result);
}
I need to make a call to a webservice and at the moment i am doing it this way:
private var myWebService:WebService = new WebService();
myWebService.loadWSDL('path to wsdl file');
myWebService.addEventListener(ResultEvent.RESULT , function(event:ResultEvent):void {
trace(event);
});
myWebService.addEventListener(FaultEvent.FAULT , function(event:FaultEvent):void {
trace(event);
});
myWebService.soapcallName();
Now i would like to do the same thing but without loading the WSDL file and doing the soapcalls directly to the right url. Is this possible?
Yes, I had to do this when our WS calls had to hit a proxy in a DMZ, but the WSDL for the ACTUAL service was behind a firewall and unreachable. But it is a tricky process.
First you will need to create the soap post requests manually. You can read all about the structure on wikipedia http://en.wikipedia.org/wiki/SOAP . This means you will need to generate all calls manually since you can't say SomeService.SomeMethod without the wsdl loaded. Now the next problem you will face is actually sending it out. Because you need to add custom http headers on a POST, you will need to build the full request document (strings and line breaks etc) and send it over a socket (HTTPService will not support custom headers on a POST). If you need more help getting this going, I can add further examples on here.
Example:
You need to basically create a method to generate SOAP Envelopes. Here's a quick i.e. from the link I gave you...
private function getStockPrice(symbol:String):String{
// you can do this with xml also and call toString() on it later
var envelope:String = "<?xml version=\"1.0\"?>";
envelope += "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">";
envelope += "<soap:Header></soap:Header>";
envelope += "<soap:Body><m:GetStockPrice xmlns:m=\"http://www.example.org/stock\">";
envelope += "<m:StockName>" + symbol + "</m:StockName>";
envelope += "</m:GetStockPrice></soap:Body></soap:Envelope>";
return envelope;
}
Then you call getStockPrice("IBM") which will return the ready to go SOAP envelope that you will use as the POST body of your call. Note that in the example, you will have to know the information that would have been in the WSDL ahead of time like method names, param names etc. Use the Socket() class to send the post body to the server since you will need to add a custom SOAPAction header. If you need help with that part, here is a class to begin hacking on that already does that... use it instead of HTTPService. RestHTTPService.
I have had this problem for some time now and I have seen others have it as well. It has to deal with posting your custom objects that you create in Open Graph to post with your application. I am having this problem primarily on all platforms, but right now let's say I am using Android. If someone has accomplished this in C# or on IOS or even in PHP please post your answer.
An Example:
I have an object that posts a meal to Facebook. Let's say its properties are the following.
mealName = "Lunch"
mealType = "Vegetarian"
mealLocation = "Somewheresville, OH"
Now I have another object in my Open Graph and it is called DailyFood. It has properties such as the following.
day = "12/01/2012"
meal = "MyCustomMeal" // This references a meal object
Now when I go to post that I try to do the following in Java.
//Build Meal
JSONObject mealData = new JSONObject();
mealData.put("mealName", "Lunch");
mealData.put("mealType", "Vegetarian");
mealData.put("mealLocation", "Somewheresville, OH");
Bundle params = new Bundle();
params.putString("day", "12/01/2012");
params.putString("meal", mealData.ToString());
AsyncFacebookRunner request = new AsyncFacebookRunner(facebook);
This is where I generate the following error code.
{"error":
{"message":"(#3503) is an invalid value for property
\"meal\" with type \"Reference\"","type":"OAuthException","code":3503}}
Now I know that it says OAuthException but I am able to post feeds to Facebook with this app just fine. If anyone else has experienced this error on any platform and has found a solution please post it here.
Thanks!
So the answer to this question is that you actually need a website available for your app to be able to reference what its posting to Facebook. In the docs, I at least, wasn't able to find out where this was noted.
according to this official video you must have the web application to post the action using open graph,no matter in which platform we are working android,ios etc
as it fetches the meta tags and properties from the web url only which works as refrence.