Tutorial : Flickr
Contents |
[edit] Flickr
In this tutorial you learn how to use Flickr to retrieve and save pictures. When you run the application and enter a search tag, Flickr returns a set of pictures that match your tag. You can click on each picture and see a larger version and you can drag pictures to build a favorites list.
Before performing this tutorial, you must obtain an API key from Flickr.
[edit] Related Resources
- For a detailed introduction to Bungee Builder, see the Introduction to Bungee Builder tutorial, which combines a guided tour of Bungee Builder with the Hello World tutorial.
- For documentation on Bungee Builder, see the Bungee documentation wiki.
[edit] How to use this Tutorial
This tutorial is written for developers that are somewhat familiar with the basics of Bungee Builder. If you would like more detailed steps on working inside Bungee Builder, check out the Introduction to Bungee Builder and Hello World Tutorial before proceeding with this tutorial.
Throughout this tutorial, there are links to reference documentation on Bungee concepts:
- Most numbered steps link to the relevant document on how to accomplish the given task. Use these links for more information on how to perform a given task (for example, how to add a class to a project).
- Beneath the steps are links to the relevant concept documents. Use these links for conceptual information on the object being used (for example, what is a class?).
[edit] Procedure
- Create a new solution and TypeLib
(Concept: Understanding Solutions and Projects)
- Solution name: Flickr
- Project type: TypeLib
- Project name: Flickr
- Add a class clsFlickrPics to the Flickr project
(Concept: Understanding Classes)
- Because you call a REST service, you must manually model the data that the service returns. Unlike SOAP-based services, REST services do not have definition files (WSDL files) that define the object type. Consequently, you manually create the class and fields for storing the data returned by the Flickr REST service. The Flicker API that you use is the flickr.photos.search API, which is documented on the Flickr Services page., which includes all the fields that you create for this class in the next few steps.
- Add a form adapter to the TypeLib
(Concept: Understanding Adapters and Connections)
- Name: PicturesElementForm
- Adapter Type: Form Adapter
- Add 10 fields to the clsFlickrPics class (these fields correspond to the XML in the Flickr response)
Note The type for the 10 fields in this step is string, the default field type.
- string id
- string medURL
- string owner
- string ownername
- string photo
- string secret
- string server
- string tags
- string thumbURL
- string title
- Add a form to the clsFlickrPics class
(Concept: Understanding Forms)
- Name: frmPicElement
- Layout: 1 row x 1 column (settings: Layout > Flow = VerticalBox, Max Height = 100, Max Width = 75)
- Add MultilineLabel
- Binding: string thumbURL
- Under Style, select HTML
- Add MultilineLabel
- Set Adapter List for frmPicElement to FormAdapter: PicturesElementForm.
- Layout: 1 row x 1 column (settings: Layout > Flow = VerticalBox, Max Height = 100, Max Width = 75)
- Name: frmPicElement
- Add a class named clsMain to the Flickr project
- Add four fields to the clsMain class
(Concept: Understanding Fields)
- Collection(clsFlickrPics): colFavoritePics (collection of your favorite pictures returned by Flickr)
- Type = clsFlickrPics (select Class: clsFlickrPics under TypeLib: Flickr)
- Select Is Collection
- Collection(clsFlickrPics): colPicList (collection of pictures returned by Flickr)
- Type = clsFlickrPics (select Class: clsFlickrPics under TypeLib: Flickr)
- Select Is Collection
- string searchTag (tag used for picture search)
- Type = string (the default type)
- clsFlickrPics selectedPic (currently selected picture from the collection)
- Type = clsFlickrPics (select Class: clsFlickrPics under TypeLib: Flickr)
- Collection(clsFlickrPics): colFavoritePics (collection of your favorite pictures returned by Flickr)
- Add a function to the clsMain class
(Concept: Understanding Functions)
- Name: cmdGetFlickrPic
- Purpose: Makes the call to Flickr
- Add a form and controls to the clsMain class
(Concept: Understanding Forms)
- Name: frmMain
- Layout: 2 rows x 3 columns
- Top row, combine cells to make one long row.
- Add Horizontal Box
- Add Text Edit
- Binding: searchTag
- Add Button
- Binding: cmdGetFlickrPics
- Button Label: Search Flickr
- Select Default property
- Add Text Edit
- Resize row (23 pixels high)
- Add Horizontal Box
- Bottom row
- Left Column (width = 100 px)
- Add DynamicFormList
- Bound to colPicList
- Element Form: PicturesElementForm (under Adapter)
- Bind Selection (set Object selectedElement to clsFlickrPics selectedPic)
- This is done by selecting the DynamicFormList and then clicking the green arrow on its upper-right corner and choosing Bind Selection.
- In the next screen, click Object selectedElement, and then in the Properties Editor, set Path to clsFlickrPics selectedPic
- Select Linked
- This is done by selecting the DynamicFormList and then clicking the green arrow on its upper-right corner and choosing Bind Selection.
- Add DynamicFormList
- Center Column (width = 238 px)
- MultilineLabel
- Bound to string medURL (found under clsFlickrPics selectedPic)
- Under Style, select HTML
- MultilineLabel
- Right Column (width = 100 px)
- DynamicFormList
- Binding: colFavoritePics
- DynamicFormList
- Left Column (width = 100 px)
- Top row, combine cells to make one long row.
- Layout: 2 rows x 3 columns
- Name: frmMain
- Edit the clsMain Class
(Concept: Understanding Bungee Logic)
- Expand public cmdGetFlickrPic
- Add five Var statements
- var XMLElement tmpPhoto
- Name: tmpPhoto
- Type: Class: XMLElement (under TypeLib: Flickr > Dependencies > Runtime > TypeLib: Utility)
- var HTTP objHTTP=newHTTP
- Name: objHTTP
- Type: Class: HTTP (under TypeLib: Flickr > Dependencies > Runtime > TypeLib: Utility)
- Default Value: Set to Object
- var XMLDocObject objXMLDoc=new XMLDocObject
- Name: objXMLDoc
- Type: Class: XMLDocObject (under TypeLib: Flickr > Dependencies > Runtime > TypeLib: Utility)
- Default Value: Set to Object
- var string response
- Name: response
- Type: string
- var XMLUtil xmlUtil=newXMLUtil
- Name: xmlUtil
- Type: Class: XMLUtil (under TypeLib: Flickr > Dependencies > Runtime > TypeLib: Utility)
- Default Value: Set to Object
- var XMLElement tmpPhoto
- Add four call function () statements
- colPicList.removeAll(void)
- Type: Path
- Select Function: removeAll (under Collection(clsFlickrPics): colPicList)
-
objHTTP.returnGet('http://api.flickr.com/services/rest/?method=flickr.photos.search&per_page=25&api_key=apikey&text=' + searchTag (where apikey is the api key you received from Flickr))
- Type: Var
- Select Function: returnGet (under HTTP objHTTP)
- Parameters
- First parameter:
- Type: Expression
- Value: 'http://api.flickr.com/services/rest/?method=flickr.photos.search&per_page=25&api_key=apikey&text=' + searchTag (where apikey is the api key you received from Flickr)
- Second parameter:
- Type: Var
- Select string response
- First parameter:
-
objXMLDoc.readString(response)
- Type: Var
- Select Function: readString (under XMLDocObject objXMLDoc)
- First parameter:
- Type: Var
- Select string response
-
objXMLDoc.root.getChild('photos',tmpPhoto)
- Type: Var
- Select Function: getChild (under XMLDocObject objXMLDoc > XMLElement root)
- Parameters
- First parameter:
- Type: Data
- Value: photos
- Second parameter:
- Type:Var
- Select XMLElement tmpPhoto
- First parameter:
- Add collection iteration
- Type: Var (Collection property)
- Select Collection(XMLElement): children (under XMLElement tmpPhoto)
- Expand the collection iteration and add the following:
- Add a Var statement
- Name: tmpPhotoResponse
- Type: Class: FlickrPics (under TypeLib: Flickr)
- Add call function ()
- Type: Var
- Select Function: convertXMLToObject (under XMLUtil xmlUtil)
- Parameters
- First parameter:
- Type: Var
- Select XMLElement CurrentElement
- Second parameter:
- Type: Type
- SelectClass: clsFlickrPics (under TypeLib: Flickr)
- Third parameter:
- Type: Var
- Select clsFlickrPics tmpPhotoResponse
- First parameter:
- Add assignment
- Left side:
- Type: Var
- Select string thumbURL (under clsFlickrPics tmpPhotoResponse )
- Right side:
- Type: Expression
- Value: "<center><img src='http://static.flickr.com/" + tmpPhotoResponse.server + "/" + tmpPhotoResponse.id + "_" + tmpPhotoResponse.secret + "_m.jpg'><br>"
- Left side:
- Add assignment
- Left side:
- Type: Var
- Select string medURL (under clsFlickrPics tmpPhotoResponse)
- Right side:
- Type: Expression
- Value: "<center><img src='http://static.flickr.com/" + tmpPhotoResponse.server + "/" + tmpPhotoResponse.id + "_" + tmpPhotoResponse.secret + ".jpg'><br>"
- Left side:
- Add call function ()
- Type: Path
- Select Function: add (under Collection(clsFlickrPics): colPicList)
- Parameter
- First parameter:
- Type: Var
- Select tmpPhotoResponse
- First parameter:
- Your class should look like this:
- colPicList.removeAll(void)
- Enable Drag-and-Drop between the two DynamicFormList controls on frmMain
(Concept: Understanding Controls)
- DynamicFormList (in left column)
- Set Drag Zone (under Behavior) to pics/Copy
- DynamicFormList on right
- Set Drag Zone (under Behavior) to favReorder/move (this enables drag and drop reorder of pictures in the favorites list)
- Set Drop Zones (under Behavior) to:
- pics/copy
- favReorder/move
- DynamicFormList (in left column)
- Run the form
(Concept: Understanding Simulate)
- Going Further
Check the Flickr documentation for information on additional data available through the method you used in this tutorial. If you would like to capture additional data (geo, tabs, owner_name, etc.) just add the correct field to the clsFlickrPics class and name it to match the response from Flickr. To display the additional data, bind it to a control and add it to your form (frmPicElement).
Flickr has many other methods you can try. See http://www.flickr.com/services/api/ for more information.