Send objects to C# code from JavaScript - c#

How can I send some object, say a JSON object, from JavaScript to my C# code for windows phone app?
I know of window.external.notify function. But this can send only string as a single parameters.
What if I want to send two different parameters?

To try answer your json question, why not serialize your object into a json string. I like to use NewtonSoft.Json to do that. Google for it or pull down with nuget. It is supported for Windows phone

Related

How to post an image to twitter from c# (unity)

I'm trying to post an image to twitter from my unity application.
My goal is to let the player tweet an image to their tweeter account.
I tried
Application.OpenURL("http://twitter.com/intent/tweet/?text=a message to be tweeted");
This is perfect because the players will have to enter their username and password in their own browser.
but I want to add an image as well.
I Tried to change the
?text=
to
?media=
I have seen in a website that twitter accepts an "media" parameter but since Application.OpenURL(""); accepts string, I couldn't pass byte[] of the image that I want to post to this URL to see whether it works or not.
I used Convert.ToBase64String(byte[] data) but for some reason, the Application.OpenURL(""); doesn't work with it. i assume it's because the length of the string that i made from the byte[] becomes so long.
I also searched google a lot for ways to login to twitter or post an image but they're mostly using third-party libararies and most of answers that are look good are written in asp mvc not unity.
thanks in advance.
Reading their documentation, if you WANT to pass the media as a string, use media_data instead of media. You will need to look online for how to convert the byte[] to a Base64 string.
https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload
Also, you will need to specify the media_category to let Twitter know that it is a tweet_image.

Metro app, parsing JSON data in C# error

I am trying to parse json data for reddit comments in a Windows 8 Metro app. I have been able to successfully parse the homepage json data using JSONObject.Parse(), but when trying to parse data for a comments page, the parse failed. The data in question is here:
Homepage: Can Parse
http://jsonviewer.stack.hu/#http://www.reddit.com/.json
Comments: Cannot Parse
http://jsonviewer.stack.hu/#http://www.reddit.com/r/leagueoflegends/comments/vt3wk/proving_grounds_playable_on_live_on_all_3_regions/.json
The problem appears to be that the root object of the comments json is an array, while the root object of the homepage is a normal object. However, jsonlint.com tells me that the json is valid in both cases.
Can anyone tell me why this occurs?
I found the answer. Instead of JSONObject.Parse, JsonArray.Parse had to be called.

How to access text inside flash object

I've got to access text inside a flash object. The preferred method is via C#, but anything that works will do. The only requirement is that I'll need the resulting information to be transferred back to c# code.
Let's take, for example, this page.
With fireflashbug, you can easily access individual elements inside flash object and read/change html texts inside each of them.
To work, it requires Flash Debugger.
How can I do the same from my own code?
You can use AS3 ExternalInterface with or without JS. Check this thread too:
C# and Flash communication
To communicate with a flash object you use Javascript.
Here are some tutorial and examples:
http://www.adobe.com/devnet/flash/articles/external_interface.html
http://csl.sublevel3.org/howto/javascript_flash_callbacks/
http://www.permadi.com/tutorial/flashjscommand/
Now, once you have your data using javascript you can pass them to an input element and pass it to code behind if you wish for.
and many more on google

Facebook Credits/Payment API in C# or VB .net?

I can't seem to find any code examples anywhere online that even hint at any way to use the Facebook API or Facebook SDK with C#.net (or even VB.net) to use the Facebook Credits features.
Does anyone know of any .Net examples that could help show how to use the Facebook Credits features?
Most of the calls required to use the credits API are actually just graph calls which will work fine with the C# SDK. The other stuff like the the callbacks you are going to have to do own your own.
Well i think the Documentation by Facebook is Sufficient enough.
I have not used Facebook C# SDK but For use in .Net you can simply use HttpRequest/HttpResponse classes to do Send/Recive data.
For parsing JSON you can use JSON.Net or use JavaScriptSerializer Class.
Here is an Example with JavaScriptSerializer. Its for Facebook Feeds but you can use somthing similar for Credits too.
I see this is an old one, i'd like to contribute, having just fought this fight, and resorted to using network monitor to capture the raw tcp traffic to figure out what was going on.
Facebook is NOT sending a content-type of json, its
"ContentType: application/x-www-form-urlencoded"
They aren't sending JSON!! they are sending a form post
This caused no end of grief for me. I'm including an actual network snag of their data. I have no idea what they are doing , and its directly against their documentation. https://developers.facebook.com/docs/credits/callback/
"signed_request=[The signed request]&buyer=[my id]&receiver=[my id]&order_id=247146405372045&order_info=%22100credits%22&test_mode=1&method=payments_get_items"
TO tie it more directly to the question, if you're using asp.net, you can just accept a form post. If you using WCF, its a hassle
Accept Stream as the input to your WCF method
parse it out,
//Get the Stream
var postStream = new StreamReader(input).ReadToEnd();
//parse the string
var vals = HttpUtility.ParseQueryString(postStream);

Is there any way I can use google-image serach API?

I want to retrive search results from google images from my .net application. Is there any way out there?
Yes, there is.
The Google Image Search API offers access through a RESTful interface, as described here, on the API reference page.
You can use e.g. the WebRequest class to make the API calls, and use one of the JSON libraries as listed on this page, such as Json.NET or JSONSharp to parse the returned JSON data.

Categories