highest safe dose of levitralevitra takecompare levitra cialis viagrageneric levitra onlinecheap herbal vardenafillevitra online uklevitra increases sperm countwomen\s vardenafillevitra samplelevitra slide kitmail order levitralevitra prescription onlinesoft levitraPurchase Levitra pillthe buy levitrageneric levitra canadaproduct team levitravardenafil 90 pills Buylevitra sale 32free sample prescription for levitralevitra trial offermedication levitranon prescription vardenafillevitra online shop in uklevitra medicareinformation levitralevitra on line saleslevitra japanqry vardenafilSale vardenafil 20 pillscheap herbal levitraidentify vardenafillevitra alternative lavitraflomax levitraGeneric Levitra 20 mg Salelevitra couponus vardenafilbuy levitra 10mglevitra commercial modelsforum levitraOnline vardenafil Courier shipping10 mg vs 20 mg levitralevitra dosage directionstoo much levitrawhere to puchase vardenafil onlinecheap levitra on linecialis levitra vardenafilhow levitra workqueen levitravardenafil 180 pills orderlevitra beogradlevitra birth control pillslevitra orallow cost alternatives and vardenafilLevitra 120 pills BuyBuy vardenafil Free Airmail shippingordering levitra onlinecialis levitra viagra comparebuy vardenafil online australiaorder levitra cheap pricevardenafil saleanyone tried generic levitravardenafil softabsbuy levitra viagra onlinelevitra user reviewneed for increasing amounts of levitralevitra online purchasewhat is vardenafilvardenafil rrp australia costvardenafil fast shippingvardenafil no prescriptionlevitra online gamblingviva levitrawomen taking levitradiscount vardenafil onlinelevitra sampleslowest price levitra generic onlinelevitra penslevitra and flomaxpurchase levitra 60 pillslevitra side effectorder Levitra 10 mgalternative to levitraby levitra priceBuy vardenafil Courier shippinguk alternative vardenafillevitra sarasota floridaprice on levitralevitra or viagra which is betterlevitra from canadalevitra ad reviewtry levitra for freeacheter du levitrawholesale vardenafillevitra where to buycomparison levitra cialistoo much vardenafilcomparison of levitra and viagradosage for levitrageneric mexican levitrahow to buy levitragenuine vardenafilcialis levitra viagra which is bettervardenafil onlinerelative costs of cialis levitraget vardenafil drug onlinelevitra vs viagra vs cialisorder levitra 30 pillssample of vardenafildiscount cialis levitra online canadanatural equivelant ingredient in levitraorder levitravardenafil 20 pills onlinecialis vardenafilreviews of viagra cialis and levitraeuropean vardenafilcanada in levitraPurchase Generic vardenafil 20 mglevitra 100mglevitra propafenoneinfo levitrauk levitra saleswoman\s levitraOnline Levitra 120 pillspurchase vardenafil 10 mggeneric levitra tab 20mgvardenafil australiacompare viagra to levitravardenafil 6 free samplesvardenafil canadian drugslevitra generikaOnline Levitra 20 mgwhat does vardenafil dovardenafil uterine thicknesslevitra hourslevitra cost of salesGeneric Levitra 10 mg ordervardenafil lengthvardenafil sideviagra cyalis levitra comparedlevitra pictureslevitra for salevardenafil online cheapLevitra 20 pills BuyLevitra Free Airmail shipping onlinebuy levitra online atgeneric levitra manufacturermaximum dosage levitravardenafil Courier shipping SaleSale vardenafil 10 pillswhat is better levitra or viagradifference between cialis levitra viagralevitracialis compare levitramedical drug levitravardenafil patent levitraprice levitralevitra tablevardenafil vs cialisvardenafil 180 pills Buyeffects of levitraget levitra drug onlinedreampharmaceuticals from levitranew erectile drug vardenafilover the counter levitrabuy levitra australiangeneric vardenafil indiacialis dysfunction erectile levitralevitra side effects visiondiscount levitra pillsOnline vardenafil Free Insurancecanadian pharmacy levitralevitra low costlevitra reviewsPurchase Generic Levitranew erectile drug levitravardenafil usevardenafil pricinglevitra herb alternativeOrder Generic vardenafil 20 mgvardenafil max complaintsfree vardenafil sampleslevitra or viagraSale Levitra 10 mglevitra lowest pricecheap vardenafil siproblems with levitralevitra suppliers in the ukwatermelon levitralevitra to buy new zealandmedicine levitralevitra 10 mg tabletbuy levitra online dream pharmaceuticalsoft levitra mastercardlevitra ingredientsvardenafil perscription onlinegeneric levitra cheapcanadian vardenafillevitra and price listvardenafil hcl 20 mgbayer levitra onlinefree trial of vardenafilbuy levitra delived fed exrecreational levitra usekey buy levitra onlinelevitrabuy cheap levitra onlineGeneric vardenafil 10 mg onlineorder cheap levitra faslevitra by bayervardenafil 30 pills onlineship free vardenafil sampleregalis vardenafilbuy levitra usvardenafil super activeLevitra 180 pills Buydrug levitra newvardenafil purchasevardenafil 30 pills orderprofessional levitra627 discount levitra online 903levitra and premature ejaculationpfizer vardenafilcialis levitra or viagralevitra twice a daysnorting levitraorder 50mg levitrabuy Levitra 10mgLevitra pills Buybuy cheap levitra onlinelevitra vs cialis reviewbrand name levitratake levitralevitra pill pricevardenafil optionslevitra cialis for womenhow to get levitravardenafil alternativespharmacy vardenafilbuy levitra ukvardenafil hcl 20mg tab side effectsbuy levitra in ukgeneric levitra professionallevitra efectosgeneric levitra effectiveorder vardenafil 10 mg2buy levitra online viagralevitra worksflomax and levitraSale Levitra Airmail shippingclinical data levitrageneric levitra soft tab fasti have levitrarx levitravardenafil 120 pillsbuy vardenafil meds onlinevardenafil online no prescriptionis vardenafil professional realcheap vardenafil walmartuk levitrabuy levitra in canadavardenafil from indiafree sample pack of levitramature vardenafilhow long is levitra effectivelevitra price comparisonlevitra storyvardenafil effekter biverkningarvardenafil for teenscheapest levitra in ukfda on levitralevitra fedexgeneric vardenafil mexicosample levitralevitra best resultslevitra substitutelevitra generic soft tabsafe maximum levitra dosagelevitra online cheapLevitra pills onlinevardenafil free sampleslevitra dysfunction erectilelevitra rxlevitra from mexicovardenafil drug prescriptionvardenafil discountsOrder vardenafil Free Insurancelevitra precautionsbuy buy cheap cheap levitra levitralevitra v s levitravardenafil sex dominationlevitra success storieslevitra for womanvardenafil 20 mg paypallevitra sverigecheap levitra overnightOrder Levitra Airmail shippingbuy vardenafil 10 pillscounterfeit levitrabuy levitra 30 pillsvardenafil suppliers in the ukvardenafil effective timeLevitra Courier shipping orderorder levitra from canadabuy drug satellite tv levitralevitra 20order vardenafillevitra wholesale onlinelevitra fast overnight delivery usa onlyuser review levitracialis and levitra generic brandgeneric levitralevitracialis generic levitra viagralevitra online usdoes levitra look likebuy levitra lowest pricescompare viagra levitralevitra on linesample of levitraviagra cialis levitra candian pharmacy safecheap vardenafil nzprice of vardenafilbuy online vardenafilnatural levitrageneric levitra pillsnatural equivalent ingredient in vardenafilordering vardenafillevitra free pillsbuy vardenafil in uklevitra order2buy generic levitralevitra pay with paypalvardenafil in uk onlineglaxo levitravardenafil and commercialvardenafil 50 mglevitra with lisinoprilwhat does levitra dobuy levitra medicationlevitra couchcan a woman take levitravardenafil 10mgreal levitralevitra offervardenafil 10 pills Buylowest prices for levitracanada vardenafilfree levitra pillscheapest online cost for levitravardenafil generic pricevardenafil gelvardenafil mexicovardenafil ukon levitralevitra discussiongeneric name of levitrabuy vardenafil 30 pillslevitra price walmartlevitra time effectiveLevitra Free Airmail shipping Salevardenafil wholesale onlinelevitra andacheter levitra francecheap vardenafil 20 mgwoman in levitra commercialpill identification levitrageneric discount levitralevitra 20 mg dosagelevitra interactionsoriginal levitrapurchase vardenafil 10mgbuy levitra online in 24 hoursvardenafil for sale without a prescriptionlevitrabuy levitra onlineLevitra 10 mg onlineviagra medication prescription levitra cialis propecialevitra anwendungviagra cialis levitra vpxlcan woman take levitrabuy levitra upsLevitra 90 pills BuySale vardenafil pillovernight vardenafilvardenafil reviewslevitra drugswatermellon vardenafilbuy levitra without prescriptionquery lowest levitra price onlinebuying levitra onlinelevitra generic priceusing levitralevitra for freegeneric viagra levitra generic cialis pillsvardenafil testimonialGeneric Levitra 20 mg ordervardenafil on linevardenafil Free Airmail shipping onlinehow long will levitra lastq buy levitraorder discount levitraviagra levitra cialis offerslevitra and bayercheap pharmacy viagra cialis levitralevitra vs viagra reviewswomans levitraburing levitra onlinelevitra softbuy cheap levitralevitra drug prescriptionbuy levitra in englandvardenafil Salevardenafil for daily useactress in levitra commercialbuy levitra with pay palcheap vardenafil overnightindia vardenafilvardenafil pill orderbuy levitra online 35008 buylevitra pill cuttervardenafil sizevardenafil uk cost pillvardenafil 60 pills onlinegeneric soft tabs vardenafilkey buy levitra cheaplevitra cheap buy onlinelow price vardenafilcheap vardenafil tabletslevitra onlinevardenafil 20 mg orderblindness cialis levitravardenafil levitra onlinelevitra faqsplitting levitravardenafil in ukvardenafil lowest priceprozac interactions with viagra cialis levitrakeywords cialis levitra sales viagrahow quick does levitra workwhat is levitra productPurchase vardenafil Free Airmail shippingLevitra 20 mgcomparison of cialis levitra and viagraovernight shipping of professional vardenafilbenefits of levitralevitra vs viagra which is better2buy cheap levitra onlinelevitra prices american pharmaciesvardenafil online overnightdiscount levitra cialis viagrabuy cheap levitra xanax xenicalorder levitra onlinecheapest vardenafil substitute vardenafilbuy vardenafil cialasbuy cheap generic levitra pharmacy onlinelevitra soft tablevitra third quarter 2004 saleslevitra bestellenvardenafil fedexviva levitra commercialLevitra Courier shipping Salecheapest vardenafil professionalLevitra 10 pills Buycheap vardenafil canadaOnline Levitra Free Airmail shippingfull information levitradiscounted vardenafillevitra substitutesLevitra 20 mg Buylevitra 20 mg bayerbuy vardenafil delived fed exforeign cialis levitra pillswomen vardenafilvardenafil overnight shippingcan women use levitravardenafil Buyvardenafil propafenonelevitra provardenafil impotence drug eli lilly cobuy levitra viagralevitra web siteship free levitra sampleorder levitra without prescriptionfree levitra onlinesuper levitralevitra in ukcompare viagra 26 levitra2cheap levitra onlineOrder vardenafilvardenafil Courier shipping orderbuy vardenafilvardenafil storieslevitra successdiscount levitra purchasecheapest levitra substitute sildenafillevitra cialis viagra comparebuy vardenafil online in ukLevitra 20 mg onlineordering levitraconnecticut levitra vardenafillevitra productsLevitra Free Airmail shipping BuyGeneric vardenafil 10 mg Sale
intense creativity » Getting around AS3’s un-RESTful-ness

Getting around AS3’s un-RESTful-ness

Hi Everyone,

[UPDATE Jan 19th, 2008]
I've just modified RESTProxy.php to handle gzip encoding from the client-side. It was quite simple. I was trying to consume web services on Discogs.com and it requires that you accept gzip encoding.. The source has been modified.

Mise en situtation
for those who have been following the development of the AS3 Youtube Data API library development, you might have seen that I hit a serious wall when I tried doing PUT and DELETE requests using flash.net.URLRequest together with flash.net.URLLoader. Simply put, it is impossible to execute such requests directly from the code library provided in Flash CS3. Some people have been trying to get around the problem using raw sockets, but will hit another wall inevitably: you are only allowed to connect raw sockets to the host that served you the .swf file. Hence, impossible to connect to gdata.youtube.com.

I had another idea, using Flex's HTTPService inside of code compiled using Flash CS3. Hit another wall there. You can dynamically load some of Flex's classes, like StringUtil, for example, using a Loader + the applicationDomain to get a reference to the Classes embedded in a SWF then instantiating them; but it doesn't work on my complex Flex classes. You get weird errors, which I don't understand. After spending a day on that, I decided it was over.

My goal was to keep this library client-side, AS3 only. I didn't mind loading a SWF to get some of it's classes, but I didn't want to use a proxy on a server... and well, it can't be done.

In comes the proxy
The idea is to provide a very general, generic proxy to help AS3 become RESTful. I had a few ideas, and in the end decided to opt for AMFPHP because of my past experience with it, and the fact that since Patrick Mineault (who has been a friend here in Montreal) has left, it seems it doesn't get much attention. AMFPHP now talks AMF3, which I think is pretty cool.

Prerequisits & Installation
In order to use this proxy you will need:

  • Access to a webserver running PHP4 or PHP5
  • The cURL library installed on your server and lib_curl running on PHP
  • To download and decompress AMFPHP on your server

Then all you need is to copy the RESTProxy.php file to your amfphp/services folder and VOILÀ! You are ready to run!

How it works
Put simply, you call a function on your RESTProxy service, which will do the call for you to the service you are trying to be RESTful with. There is complete flexibility here, you can do everything you want. The service then returns all the information required to parse the answer from the service. This makes it so much easier, since it handles all the HTTP Response codes w/o making a fuss (like URLLoader would when it receives a 201 Created code for example. Everything is transparent.

Here is the service's signature

PHP:
  1. public function request($uri, $method = "GET", $getVars = array(), $postVars = array(), $headers = array())

The getVars is an array of string in the same format you would see them in a URL : countedHits=329. Same for the postVars.

The headers is an array of string each in the same format as the actual HTTP headers: Keep-alive: false.

and the returned values

PHP:
  1. return array("header" => $headersIn,
  2.          "content" => $result,
  3.          "httpCode" => $code,
  4.          "contentType" => $contentType,
  5.          "effectiveUrl" => $effectiveUrl,
  6.          "sentHeaders" => $headersOut);

Sample usage
Here is some source code that describes how to use it. This particular code will log you into the Google Data webservice so that you can use the YouTube services. (Please replace USERNAME & PASSWORD to by your YouTube credentials for it to work).
You can download the source file here.

Actionscript:
  1. public class RESTProxyTest extends MovieClip
  2. {
  3.     protected var _url:String = "http://www.martinlegris.com/amf3/gateway.php";
  4.     protected var _conn:NetConnection;
  5.     protected var _responder:Responder;
  6.    
  7.     public function RESTProxyTest()
  8.     {
  9.         _conn = new NetConnection();
  10.        
  11.         _conn.addEventListener(AsyncErrorEvent.ASYNC_ERROR, doAsyncError);
  12.         _conn.addEventListener(IOErrorEvent.IO_ERROR, doIOError);
  13.         _conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doSecurityError);
  14.         _conn.addEventListener(NetStatusEvent.NET_STATUS, doNetStatus);
  15.         _conn.objectEncoding = ObjectEncoding.AMF3;
  16.        
  17.         _conn.connect(_url);
  18.         _responder = new Responder(onResult, onFault);
  19.        
  20.         placeCall();
  21.        
  22.     }
  23.    
  24.     protected function placeCall():void
  25.     {
  26.         trace("placeCall");
  27.         var headers:Array = ["Content-Type: application/x-www-form-urlencoded"];
  28.         var postVars:Array = [ "Email=USERNAME",
  29.                         "Passwd=PASSWORD",
  30.                         "service=youtube",
  31.                         "source=youtube_discovery_test" ];
  32.                         
  33.         var uri:String = "https://www.google.com/youtube/accounts/ClientLogin"
  34.  
  35.         _conn.call("RESTProxy.request", _responder, uri, "POST", new Array(), postVars, headers);
  36.     }
  37.    
  38.     protected function doAsyncError(evt:AsyncErrorEvent):void
  39.     {
  40.         trace("AsyncError:" + evt.error);
  41.     }
  42.    
  43.     protected function doIOError(evt:IOErrorEvent):void
  44.     {
  45.         trace("IOError:" + evt.text);
  46.     }
  47.    
  48.     protected function doSecurityError(evt:SecurityErrorEvent):void
  49.     {
  50.         trace("SecurityError:" + evt.text);
  51.        
  52.     }
  53.    
  54.     protected function doNetStatus(evt:NetStatusEvent):void
  55.     {
  56.         trace("NetStatus:" + evt.info);
  57.        
  58.         for (var i in evt.info)
  59.         {
  60.             trace(i + ":" + evt.info[i]);
  61.         }
  62.     }
  63.    
  64.     protected function onResult(result:Object):void
  65.     {
  66.         trace("onResult");
  67.         for (var i in result)
  68.         {
  69.             trace(i + ":" + result[i]);
  70.         }
  71.     }
  72.    
  73.     protected function onFault(fault:Object):void
  74.     {
  75.         trace("onFault");
  76.         //fault.description..
  77.     }      
  78. }

Reserves

You can use mine for testing purposes: http://www.martinlegris.com/amf3/gateway.php . However PLEASE install it on your server once you start being serious about it. If there is abuse I will remove it.

I did NOT test it on PUT requests with content yet, and I am very curious to see if it'd be possible to do file uploads using this service. I think so. If anybody tries it before me, please let me know!

Cheers!

18 Responses to “Getting around AS3’s un-RESTful-ness”

  1. Sönke Rohde says:

    cool stuff! using amfphp as a proxy is really a good idea.

  2. Sergio says:

    any progress at uploading videos? I can’t send multipart/related forms without getting an IO error… (error 400 google)

  3. xleon says:

    Hi, I was looking for a getter in your VideoData.as class to find the .flv url to directly load a video into my app but I didn´t find it.
    I´ve seen some samples to do this (http://thanksmister.com/examples/flexyoutube/srcview/index.html)
    and it would be good to be inside your api.

  4. mlegris says:

    xleon: I will add it to the next update. For now you have the .swfUrl easily accessible on all VideoData types. I didn’t put the flvUrl because you needed to hack it (get a special id code from the webpage containing the video on youtube) and append it to the flvUrl in order to play it. Otherwise it will not work. Maybe this has changed. I will look into it and post a solution next week.

    been busy…

    :)

  5. xleon says:

    Great! that would be nice, and I hope it has changed. because I don´t see other way to make a youTube app without youTube logo and info without that.

  6. Helmut Granda says:

    @xleon

    Although you can “hack” the way to get the FLV url I don’t think it is acceptable. I haven’t read all the Terms and Copyright policies from Youtube but one way that they make money out of the site is by allowing you to play the videos within their interface. Trying to get the FLV without using their interface it would be stealing bandwidth, as simple as that.

    Now, if you don’t like Youtube’s player/interface but still want to have your videos online you can upload your videos to your server and use those instead with your own player/interface.

  7. erick says:

    I tried to get the proxy script to work on various servers set up with php but I never get anything returned?! is there something I’m missing from this setup?? I’d love to get this proxy implemented cuz then i could modify it for diff services…
    any help would be appreciated..
    p.s. i know the problem isn’t that clear but I’ve tried so many options i’m basically..out of options :)
    cheers
    erick

  8. Ad says:

    Hello All

    First of all thanks to martin for doing this great work really good.

    Secondly Can anyone please tell me whether you need this rest webservice to retrieve information from youtubeAPI or is this a seperate thing?

  9. mlegris says:

    Hey Ad,

    the answer is: if you just want to get data from the youtubeAPI, you don’t need to use RESTProxy, however if you want to commit data (log a user in, modify his favorites, add videos), then you do need RESTProxy.

    :)

  10. alekkus says:

    Thanks Martin. I used your script to read feeds from Friendfeed since they don’t host a cross-domain file. Check it out at http://alekkus.com/blog/2009/02/hooking-up-to-friendfeed-api/

    One issue came up though; unicode/non-latin characters got messed up. I overcome it by inserting $result = rawurlencode( $result ). Then on the Flex side, I used decodeURIComponent( result ) to decode it. Works well so far.

    Once again, thanks for sharing.

  11. mrming says:

    Hi Martin,

    I’d like to use your YouTube data API in a Flash project but I’m hoping to use the new features of the API such as adding comments. Do you have an ETA for when these will be implemented?

    :-)

  12. Michael Christoff says:

    Why don’t you just pull the HTTPService class out of flex. The framework is open source so it shouldn’t be too big of a deal. The proxy solution, while clever, presents major issues if you’re writing anything for scale.

  13. mlegris says:

    @Michael

    I tried extracting HTTPService from Flex, lost 1.5 days and got nowhere. Flex is very much spaghetti code (yes, somebody has to say it!). If anybody succeeds at doing this, please show me how!

  14. shibby says:

    Has somebody actually tried to do the upload part with the RESTProxy?

    I’m very interested on it, but all my tries were unsuccessful. I’ve seen in the AS3 Youtube Data API that xml content is sent to RESTProxy as postvars, so it’s not the same to get an upload token or to upload a file?

    Please somebody help me

  15. Arpit says:

    I think, this is a Flash player problem rather then Flash CS3. You will have same issues if you use Flex.

    However, instead of using a server side proxy, you could call restful service from JavaScript and use the results in Flash using ExternalInterface. Isnt that true?

    Here is a link to an example with Flex client using Restful service using JS / ExternalInterface.

    I don’t see any problems implementing the same in Flash though personally I have not done this yet…

  16. Arpit says:

    And here is the link which explains how to use Flex classes within Flash:

    http://labs.wichers.nu/2007/12/25/using-flex-compiled-code-within-flash/

    I implemented this successfully for WebService class within Flex.

  17. Arpit says:

    Oops, forgot to post the link for Flex / Restful example with JS and ExternalInterface, here it is:

    http://www.uiandtherest.com/ui/index.php/2009/06/18/flash-player-and-rest-issue-work-around/

  18. jan wichers says:

    [...] om net als bij Unite de … Paul Tondeur // Jan 31, 2009 at 9:52 pm. Er is gefilmt gedurende de …intense creativity Getting around AS3’s un-RESTful-ness[UPDATE Jan 19th, 2008] I’ve just modified RESTProxy.php to handle gzip encoding from the … [...]

Leave a Reply