Archive for the 'Pownce' Category

03
Mar

Pownce Actionscript 3 Library Released - Full API V2.0 Implementation (Upload files and everything)

Now that Pownce has released an official API covering features such as posting files, I decided to go ahead and make an AS3 library for it. I just posted it to googlecode and have only done minimal testing on it. I would appreciate any feedback.

The Pownce team did a terrific job with the API. Easy to use and consistent. I had minimal issues while creating the as3 library.

In my opinion (yeah you can skip this) Pownce is a far better user experience than Twitter. Its like a gobot and a transformer or a dell laptop and a macbook or chocolate torte and hohos. That is the best I an come up with that the moment, yes.

torteHoHos

I could be missing something here… but this API in my mind is a leap forward in the race with twitter.

// Imports omitted for brevity
private const APP_KEY:String = "<your app key>";
 
private var _pownceService:PownceService;
private var _testUsername:String = "<Pownce username>";
private var _testPassword:String = "<Pownce password>";
 
private function initApp():void{
	_pownceService = new PownceService(APP_KEY);
	_pownceService.setAuth(_testUsername, _testPassword);				
}
 
// Example of posting a file
public function testPostAFile():void{
	var file:FileReference = new FileReference();
 
	_pownceService.addEventListener(PownceResultEvent.ON_POST_A_FILE, function(event:PownceResultEvent):void{
			var pownceResult:PownceNotesResult = event.data as PownceNotesResult;
 
			if(pownceResult.success){
				trace((pownceResult.notes[0] as PownceNote).body);
			}else{
				trace(pownceResult.statusCode);
				trace(pownceResult.message);
				trace(pownceResult.request);
			}
		});
 
	file.addEventListener(Event.SELECT, function(event:Event):void{
			_pownceService.postAFile("all", event.currentTarget as FileReference, "File upload test");
		});
	file.addEventListener(ProgressEvent.PROGRESS, function(event:ProgressEvent):void{
			trace(event.bytesLoaded + "/" + event.bytesTotal);
		});
 
	file.browse();
}
private function testGetNoteList():void{
 
	_pownceService.addEventListener(PownceResultEvent.ON_GET_NOTE_LIST, function(event:PownceResultEvent):void{
			var pownceNoteResult:PownceNotesResult = event.data as PownceNotesResult;
 
			if(pownceNoteResult.success){
				trace(pownceNoteResult.notes.length);
			}else{
				trace(pownceNoteResult.statusCode);
				trace(pownceNoteResult.message);
				trace(pownceNoteResult.request);
			}
		});
 
	_pownceService.getNoteList(_testUsername,null, 100, -1, -1);
}

I’m going to continue to test the library and improve the documentation. Let me know if I missed anything (outside of OAUTH).

Add me to your Pownce http://pownce.com/InitApp/

Existing issue:
One method is not currently working. It is the retrieval of the send to list. I’ve posted information about the issue to the google pownce group and hopefully it will be resolved soon.

29
Feb

Posting a Note/Link to Pownce with ActionScript and the New Pownce v2.0 API

So this morning Pownce finally released a true API that allows us to use the full functionality of Pownce. A while back I posted information on how to do this in a reverse engineered method, but now we can do it without the feeling that we might be doing something bad (although that can be fun sometimes to can’t it).

The code sample below shows how to Authenticate to the service using HTTP Basic Authentication and posts a note/link.

Steps to take
1. Get a pownce account if you don’t have one.
2. Register to get an application key.
3. Use the following code. Change “app_key” to your application key. Change “login” and “password” to user you want to post with.


Private Paste Link to Code

import mx.utils.Base64Encoder;
 
private const APP_KEY:String = "<app_key>";
 
public function initApp():void{
	sendNote(
		"Example of note in the new API.",
		"http://pownce.com/initapp",
		"<login>",
		"<password>"
		);
}
public function sendNote(note:String, link:String, login:String, password:String):void{
	var urlLoader:URLLoader = new URLLoader();
	var urlRequest:URLRequest = new URLRequest();
	var urlVariables:URLVariables = new URLVariables();
 
	var authHeader:URLRequestHeader = new URLRequestHeader("Authorization", "Basic " + base64Encode(login + ":" + password));
 
	urlVariables.note_to = "public";
	urlVariables.url = link;
	urlVariables.note_body = note;
 
	urlRequest.requestHeaders.push(authHeader);
	urlRequest.url = "http://api.pownce.com/2.0/send/link.xml?&app_key=" + APP_KEY;
	urlRequest.data = urlVariables;
	urlRequest.method = URLRequestMethod.POST;
 
	urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus);
	urlLoader.addEventListener(Event.COMPLETE, onComplete);
 
	urlLoader.load(urlRequest);
}
private function onHTTPStatus(event:HTTPStatusEvent):void{
	trace(event);
}
private function onComplete(event:Event):void{
	trace(event);
}
private static function base64Encode(data:String) : String
{
    var encoder:Base64Encoder = new Base64Encoder();
	var bytes:ByteArray = new ByteArray();
	bytes.writeUTFBytes(data);
 
    encoder.encodeBytes(bytes);
    return encoder.flush();
}

If you want to hear more of my occasionally relevant information then add me to your friends in pownce: http://pownce.com/InitApp/


Note: I did this example using Flex and used mx.utils.Base64Encoder. If you’re not using Flex you’ll need to use an alternate package for your Base64 encoding.




flickr