Skip navigation
Currently Being Moderated

Adding Flickr feed to iPhone app in AS3

Mar 9, 2012 10:29 AM

Tags: #app #as3 #iphone #flickr

I am fairly new to AS3 but I have been able to build a somewhat dinky app for iPhone and Andoid with Flash CS5.5, and I am wanting to add my Flickr feed to it.  Does anyone know of any good tutorials out there for this?  I am completely stuck. I tried going through Flickr's API but that didn't help out so much.

 

Thanks in advance for any help you can throw my way!

 
Replies
  • Currently Being Moderated
    Mar 11, 2012 1:15 AM   in reply to Claunchster

    I would recommend going one step at a time. Learn how to create your own custom classes, learn OOP before stepping into the flickr API. However, if you really want to see how it is done, here's some sample actionscript that I found on the Tour de Flex app.

     

    import com.adobe.webapis.flickr.events.FlickrResultEvent;

                                  import com.adobe.webapis.flickr.*;

     

                                  import mx.controls.Alert;

     

                                  private var service:FlickrService;

     

                                  private var queriedUser:String = "tourdeflex";

     

                                  private var photosArray:Array;

     

                                  private var flickrId:String;

     

                                  private function init():void

                                  {

                                            /**

                                             * You need to provide your own API keys here in order for the

                                             * test to run.

                                             *

                                             * http://www.flickr.com/services/api/auth.howto.desktop.html

                                             */

                                            var api_key:String = use your own API key here

                                            service = new FlickrService( api_key );

                                            service.secret = use your own secret here

                                            service.addEventListener( FlickrResultEvent.AUTH_GET_FROB, onAuthGetFrob );

                                            service.auth.getFrob();

                                  }

     

                                  private function onAuthGetFrob( event:FlickrResultEvent ):void {

                                            if (event.success) {

                                                      var frob:String = String( event.data.frob );

                                                      onGet(null);

                                            }

                                  }

     

                                  /**

                                   * Note: This API requires the userid/pw to be logged in thru the flickr website to access

                                   *                      many methods, but some public methods are available just by username, such as below.

                                   */

                                  private function onGet(event:Event):void

                                  {

                                            if (userid.text!=null && userid.text.length >0) {

                                                      service.addEventListener( FlickrResultEvent.PEOPLE_FIND_BY_USERNAME,onPeopleFindByUsername);

                                                      service.people.findByUsername( userid.text );

                                            }

                                            else Alert.show("Please enter a flickr userid.");

                                  }

     

                                  private function onPeopleFindByUsername(event:FlickrResultEvent):void

                                  {

                                            var user:User = event.data.user;

                                            if (user != null) {

                                                      flickrId = user.nsid;

                                                      service.addEventListener(FlickrResultEvent.P EOPLE_GET_PUBLIC_PHOTOS, genericResponseHandler);

                                                      service.people.getPublicPhotos(flickrId);

                                                      queriedUser=userid.text;

                                            }

                                            else {

                                                      Alert.show("Flickr userid " + userid.text + " not found.");

                                                      this.queriedUser = "";

                                                      this.resultPanel.title="";

                                                      this.dgData.dataProvider = new Array(); //clear the dg

                                            }

                                  }

     

     

                                  /**

                                   * Generically handle the response to a flickr method call - just output

                                   * the information in the event to the screen.

                                   */

                                  private function genericResponseHandler( event:FlickrResultEvent ):void

                                  {

                                            if ( event.success ) {

                                                      if (event.data.photos is PagedPhotoList)

                                                      {

                                                                var list:PagedPhotoList = PagedPhotoList(event.data.photos);

                                                                this.dgData.dataProvider = list.photos;

                                                      }

                                            }

                                            else {

                                                      // Encountered some kind of error on Flickr...

                                                      var e:FlickrError = FlickrError( event.data.error );

                                                      Alert.show("Flickr API error: " + e.errorMessage);

     

                                            }

                                  }

                                  public function createUrl(server:String, photoId:String, secret:String):String

                                  {

                                            // Create the URL to the thumbnail based on the photo info

                                            var url:String = "http://farm4.static.flickr.com/"+server+"/"+photoId+"_"+secret+"_t.jpg";

                                            return url;

                                  }

     

    You'll still need to work out how to display the information, but at least all of the code for pulling the feed is here.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points