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 » Youtube Data API AS3 - First Tutorial

Youtube Data API AS3 - First Tutorial

Hi everyone,

In this tutorial I will demonstrate how to use the YouTube Data API AS3 Library to:

  • search for videos using a keywords, categories and tags;
  • demonstrate how to distinguish between feeds returned to you by the API by using the requestId;
  • get information from the result feed, in this case a VideoFeed object. We will get the video, it's main URL, then go through the different thumbnails available for a specific video.

So let's get started

Actionscript:
  1. package ca.newcommerce.youtube
  2. {
  3.     // the different imports we will be needing
  4.     import ca.newcommerce.youtube.data.ThumbnailData;
  5.     import ca.newcommerce.youtube.data.VideoData;
  6.     import ca.newcommerce.youtube.events.VideoFeedEvent;
  7.     import ca.newcommerce.youtube.feeds.VideoFeed;
  8.     import ca.newcommerce.youtube.iterators.ThumbnailIterator;
  9.     import ca.newcommerce.youtube.webservice.YouTubeClient;
  10.  
  11.     // our class
  12.     public class SearchSample
  13.     {
  14.         // the web service client reference
  15.         protected var _ws:YouTubeClient;
  16.  
  17.         // an id to identify our request
  18.         protected var _requestId:Number;

So far we've defined our class, SearchSample, and two member variables: _ws (which will contain a reference to the YouTubeClient singleton) and _requestId (to store the unique id associated with our specific request).

Next we will get a reference to the YouTubeClient class, listen for the proper event, launch our search request and store the requestId associated with it.

Actionscript:
  1. // the constructor to our sample
  2.         public function SearchSample()
  3.         {
  4.             // get a reference to the YouTubeClient instance
  5.             _ws = YouTubeClient.getInstance();
  6.            
  7.             // listed for the proper event to be fired by the client,
  8.             // the function "doSearchResults" will be called once the results are received
  9.             _ws.addEventListener(VideoFeedEvent.VIDEO_DATA_RECEIVED, doSearchResults);
  10.  
  11.             // search for the string : "american idol"
  12.             // while not specifying an author
  13.             // while not specifying any categories
  14.             // look for videos tagged with "music"
  15.             // and not tagged with "male"
  16.             // order by view count
  17.             // include restricted material
  18.             // finally store the resulting requestId inside of SearchId.
  19.             _requestId = _ws.getVideos("american idol", "", null, null, ["music"], ["male"], YouTubeClient.ORDER_BY_VIEWCOUNT, YouTubeClient.RACY_INCLUDE);
  20.  
  21.         }

Now on with the event handler, doSearchResults. We will:

  • make sure we are treating the right request, since YouTubeClient is a singleton, this can become important when you have multiple calls being made from different places in your program.
  • get a reference to the VideoFeed object contained inside of the VideoFeedEvent object passed as a parameter to the event handler.
  • create a variable to contain the VideoData objects describing the videos received in the results
  • iterate through the first set of results (since we are getting the first 50 by default
  • see some useful variables such as the Title of the video and it's author's name
  • get a reference to the ThumbnailIterator which will give us access to all available thumbnails
  • create a variable to contain ThumbnailData objects which describe each thumbnail available

Actionscript:
  1. // our function definition, note the evt variable is of type VideoFeedEvent
  2.         protected function doSearchResults(evt:VideoFeedEvent):void
  3.         {
  4.             // check to see if this request's response is the right one
  5.             if(_requestId == evt.requestId)
  6.             {
  7.                 // get a reference to the VideoFeed
  8.                 var feed:VideoFeed = evt.feed;
  9.  
  10.                 // prepare a variable to hold the individual Video's data.
  11.                 var video:VideoData;               
  12.                
  13.                 // iterate through the feed results
  14.                 while(video = feed.next())
  15.                 {
  16.                     // video title
  17.                     video.title;
  18.                    
  19.                     // video author's name
  20.                     video.authors.first().username;
  21.                    
  22.                     // get a reference to the ThumbnailIterator
  23.                     var tnIt:ThumbnailIterator = video.media.thumbnails;
  24.  
  25.                     // prepare a variable to hold the individual thumbnail's data
  26.                     var tn:ThumbnailData;
  27.                    
  28.                     // iterate through each thumbnail
  29.                     while(tn = tnIt.next())
  30.                     {
  31.                         // thumbnail url
  32.                         tn.url
  33.                        
  34.                         // thumbnail width
  35.                         tn.width;
  36.                        
  37.                         // thumbnail height
  38.                         tn.height;
  39.                        
  40.                         // thumbnail time sequence
  41.                         tn.time;
  42.                     }
  43.                 }
  44.             }
  45.             else
  46.             {
  47.                 trace("this request:"+evt.requestId+" is not ours. we'll wait for the next one");
  48.             }
  49.         }
  50.     }   
  51. }

That's it folks! The project is now available at Google Code, here: http://code.google.com/p/as3-youtube-data-api/

I could use help with documentation, if anybody feels up to the task, leave your email or contact info in a comment!



Related posts (automatically generated):

  1. YouTube Data API ActionScript 3
  2. Youtube Data API in AS3 is ready!
  3. Youtube Data API AS3 - YouTubeClient functions & associated events.
  4. YouTube Data API - new rollout
  5. Sample Code - Using the YouTube AS3 API with the YouTube Player API


18 Responses to “Youtube Data API AS3 - First Tutorial”

  1. Gonzalo Geraldo says:

    Hello, Im trying to play with this great library but i cant make it work on browser…inside flash everything its fine. Its crossdomain working???

    thanks

  2. gonzalo Geraldo says:

    sorry, sorry, sorry

    i just read the previuos post :( and its working really fine !!!!

    thanks a lot

  3. Alan Jenkins says:

    Getting the following error on doLogin:
    WSClient.doHttpStatus:200
    doLogin
    ArgumentError: Error #2096: The HTTP request header Authorization cannot be set via ActionScript.
    at flash.net::URLStream/load()
    at flash.net::URLLoader/load()
    at ca.newcommerce.youtube.webservice::YouTubeClient/runLoader()
    at ca.newcommerce.youtube.webservice::YouTubeClient/rate()
    at ca.newcommerce.youtube::Test/doLoggedIn()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at ca.newcommerce.youtube.webservice::YouTubeClient/doLogin()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    Can you advise please? Thanks

  4. Pedro says:

    when I try to load video.swfUrl on stage, it displays a warning in debug:

    Warning: Domain i.ytimg.com does not specify a meta-policy. Applying default meta-policy ‘all’. This configuration is deprecated. See http://www.adobe.com/go/strict_policy_files to fix this problem.

    Do you can help me?

  5. mlegris says:

    Alan,

    I am working on a version which uses a AMFPHP Proxy. This problem you had is caused by the security sandbox from the Flash Player, by using a proxy we have complete freedom. In PHP and most other programming languages you don’t have these (stupid) limitations. I use cURL to make the requests, and return the responses using AMFPHP. It works quite nice. I recently posted on it. The API will be updated shortly.

  6. mlegris says:

    Pedro,

    this problem is due to the crossdomain.xml policy file found on i.ytimg.com, over which I have no control. I suggest posting this comment in the google group on the Youtube Data API developer forum.

  7. dehash » YouTube API Resources « says:

    [...] Youtube Data API AS3 - Tutorial [...]

  8. Lyn says:

    Hi,

    Great post! Have you updated API with the fix for policy issue?

  9. Patrick says:

    Hi,

    i really liked this AS3 Classes, but i can´t download from code.google…there is a problem? -

  10. Bernie says:

    Hello,
    I’m a AS3 new beginner and I’ve read your sample code in this article. But when I press Ctrl + Enter to test, it show: “Error:5000, it must have sub-class “flash.display.MovieClip”
    Then I import flash.display.MovieClip, but still pop the same error code 5000. Could you kindly give me some suggestions?
    Thanks a lot!!

  11. CarlosM says:

    Hi,

    I tried to use the method getVideo from YouTubeFeedClient class, but I have the next message:

    WSClient.doHttpStatus:200
    doVideoLoaded

    The code it is the follow:

    _ws = YouTubeClient.getInstance();
    _ws.addEventListener(VideoFeedEvent.VIDEO_DATA_RECEIVED, doSearchResults);

    _requestId = _ws.getVideos(”uEGPF1be6RM”);

    anyone know, what happend?

    Reagards.

  12. Tutorials | AS3 and AMFPHP Roundup « Flash Enabled Blog says:

    [...] Youtube Data API AS3 [...]

  13. niklas wörmann says:

    Hi!
    Impressive work indeed, and its really amazing the kind of interaction with Youtube you can acchieve.

    I am having a really annoying problem though, where amidst all the data can I retrive the URL to the netstream I need to connect my Video player to actually play the stream?

    TIA
    Niklas Wörmann
    Sweden

  14. Flash Tips » AS3 and AMFPHP roundup says:

    [...] Youtube Data API AS3 [...]

  15. CrazyDave says:

    Okay…I think I must be a complete idiot, cause I’m really having a hard time getting this. (Though I’m making progress)

    I’m trying to get a the ten most recently uploaded videos from a particular youtube account, and I just can’t seem to make it happen.
    (I think I need to use “VideoFeedEvent.VIDEO_DATA_RECEIVED”, but I’m not sure how to do it…)

    So far, this is the most mack-daddy site that I’ve found for the youtube API. Can somebody please help me? PLEASE!!!

  16. CrazyDave says:

    Okay…I figured it out. The latest download (0.95) gets a little confused, because the test files and classes are trying to access YouTubeClient.as and it doesn’t exist anymore. (They are now YouTubeDataClient.as & YouTubeFeedClient.as)

    Simply switch it to the most appropriate file and you’ll be golden.

    Now, if I can just figure out how to attach my new content to items on my stage I’ll be crazy happy!

  17. CrazyDave says:

    Two days later…still trying to figure out the getAt method. ARGH!!!

    I think that’s how I need to call specific lines from the feed.

  18. cypress says:

    Great work!!! works great in flash builder 4 too

Leave a Reply