Created
March 2, 2010 21:28
-
-
Save RandomEtc/319970 to your computer and use it in GitHub Desktop.
really simple Flickr API code for as3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flickr:Flickr = new Flickr('YOUR_KEY_HERE'); | |
flickr.call('flickr.people.findByUsername', { username: 'Steve Coast' }, function(event:Event):void { | |
var rsp:XML = XML(event.target.data); | |
var userId:String = rsp.user[0][email protected](); | |
flickr.call('flickr.photos.search', { user_id: userId, has_geo: 1, extras: 'geo' }, function(event:Event):void { | |
var rsp:XML = XML(event.target.data); | |
for each (var photo:XML in rsp.photos.photo) { | |
var lat:Number = parseFloat(photo.@latitude); | |
var lon:Number = parseFloat(photo.@longitude); | |
var title:String = [email protected](); | |
var url:String = flickr.getURL(photo, '_t') | |
// now do something with the picture, whatever you like | |
} | |
}); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.events.ErrorEvent; | |
import flash.events.Event; | |
import flash.events.IOErrorEvent; | |
import flash.events.SecurityErrorEvent; | |
import flash.net.URLLoader; | |
import flash.net.URLRequest; | |
import flash.net.URLVariables; | |
public class Flickr | |
{ | |
public var base:String; | |
public var key:String; | |
public function Flickr(key:String, base:String='http://api.flickr.com/services/rest/') | |
{ | |
this.key = key; | |
this.base = base; | |
} | |
public function call(method:String, params:Object, completeEventHandler:Function, errorEventHandler:Function=null):void | |
{ | |
var loader:URLLoader = new URLLoader(); | |
var request:URLRequest = new URLRequest(base); | |
var data:URLVariables = new URLVariables(); | |
data['method'] = method; | |
data['api_key'] = key; | |
for (var prop:String in params) { | |
data[prop] = params[prop]; | |
} | |
request.data = data; | |
loader.addEventListener(Event.COMPLETE, completeEventHandler); | |
if (errorEventHandler != null) { | |
loader.addEventListener(IOErrorEvent.IO_ERROR, errorEventHandler); | |
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorEventHandler); | |
} | |
try { | |
loader.load(request); | |
} | |
catch (error:Error) { | |
if (errorEventHandler != null) { | |
errorEventHandler(new ErrorEvent(ErrorEvent.ERROR, false, false, error.message)); | |
} | |
} | |
} | |
// size can be _m, _s, _t, or _b | |
// no support for original here | |
public function getURL(photo:XML, size:String=''):String | |
{ | |
var farmId:String = [email protected](); | |
var serverId:String = [email protected](); | |
var id:String = [email protected](); | |
var secret:String = [email protected](); | |
return 'http://farm'+farmId+'.static.flickr.com/'+serverId+'/'+id+'_'+secret+size+'.jpg'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment