Thanks for the tip Roan, but I'm afraid I'm still having trouble with this. I just spent the last couple hours researching JSON callbacks, as I have never had a need to learn about it more until now. I'm specifically trying to pull the information from within a Flash AS3 program, so I also did a bit of research about reading and decoding JSON with ActionScript 3. Unfortunately, I just appear to be spinning my wheels and not making any real progress. I'm sure I'm doing something wrong, but haven't yet been able to figure out what that is. Hopefully somebody here might be able to spot it.
Here's a link to the tutorial I'm using for using JSON with AS3, but will summarize for brevity.
(http://www.cakesgood.com/2009/04/flash-cs3-actionscript-30-json-keep-it_3277.html)
We basically use Flash's net classes to request the contents at the specified URL and then decode the expected JSON response using the Adobe core library (downloadable from the tutorial). Here is the resulting ActionScript 3 code:
/////////////////////////////////////////////////////////////AS3\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
import com.adobe.serialization.json.JSON;
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest();
request.url = "http://en.wiktionary.org/w/api.php?format=json&callback=myFunc&action=opensearch&limit=1&search=play" ;
loader.load(request);
loader.addEventListener(Event.COMPLETE, decodeJSON);
function decodeJSON(event:Event):void {
trace(event.target.data);
var loader:URLLoader = URLLoader(event.target);
var People:Array = JSON.decode(loader.data);
trace(People);
}
/////////////////////////////////////////////////////////////AS3\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
This results in a parse error and printing out the loader.data will display:
myFunc(["play",["play"]])
I suspect this is due to an incorrect usage of the API call, but further testing and research have not produced any better results. I can't seem to get any JSON formatted call to return any contents from the page. During my research I stumbled on a collection of mediawiki-api emails where another developer (Borort) was having trouble converting XML to JSON and explained his reason for not exporting directly to JSON as: (http://old.nabble.com/Problem-converting-new-XML-format-to-JSON-td24242786.html)
"The reason that i don't use format=json
is it will not return the description and url of the result.."
Roan's response to this was:
"Actually, both the JSON opensearch format
and the XML opensearch
format are documented standards, but with different
fields. IIRC, the
opensearch module will refuse to output anything but
these two, and
will output JSON even if you
set format=php. It's only intended to be
used for browser search plugins (JSON
for Firefox, XML for IE); for
other purposes, you're probably better off using
list=search or
list=allpages&apprefix=Foo instead.
Roan Kattouw (Catrope)"
Am I simply using the incorrect api calls for this? Or should I be approaching this from an entirely different angle? The end goal is to search Wiktionary for the definition of a dynamically submitted word from within a Flash AS3 program, so I don't think there should be any problems with restricted information.
Thanks again,
Aaron.
2010/6/9 Aaron Ward <edugamer@gmail.com>:
> I finally had the time to dive back into this project and managed to getYou can use JSON callbacks, which basically means you (dynamically)
> everything working exactly as I was hoping.... locally! After uploading the
> game to a server it suddenly stops working again. From my knowledge with
> Flash games and further testing, I believe it has to do with the
> cross-domain-policy for Wikitionary, which is usually an xml set up on the
> server.
>
> While attempting to locate the current Wikimedia policy I ran into random
> comments with warnings about the security risks involved in using the
> cross-domain-policy. I also discovered that Bugfix 1.9 states "Partial
> support for Flash cross-domain-policy filtering."
>
> I'm not sure where to go from here. Is there a confirmed and allowed method
> to programmatically pull the rendered HTML from Wiktionary that can then be
> parsed?
>
add something like this to the HTML of your page:
<script type="text/javascript"
src="http://en.wiktionary.org/w/api.php?format=json&callback=myFunc¶metersHere"></script>
Which will cause the function myFunc() to be executed with the results
of the API call passed as a parameter. However, for security reasons,
all callbacks will be treated as originating from anonymous users, and
they can't be used to get restricted informations, get tokens, edit
stuff or anything like that.
Roan Kattouw (Catrope)
_______________________________________________
Mediawiki-api mailing list
Mediawiki-api@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api