Using BlackBerry ID in your PlayBook Application
The latest release of the PlayBook’s BlackBerry Tablet OS SDK for AIR provides some new APIs. One of the newer BlackBerry APIs is around getting BlackBerry ID information. You can test the API calls that integrate the PlayBook user’s BlackBerry ID information in your application.
This is what it looks like for a user to sign into their BlackBerry ID from the PlayBook simulator (this is a system dialog and developers can’t change it):
To prompt the “sign in” dialog and receive the BlackBerry ID information for the user of the PlayBook see the following ActionScript API. I went ahead and wrote up some simple code to show how it works (also available in my github here):
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
applicationComplete="windowedapplication1_applicationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import net.rim.blackberry.bbid.BBIDProfile;
import net.rim.blackberry.bbid.UserProperty;
import net.rim.blackberry.events.BBIDEvent;
private var bbidprofile:BBIDProfile;
protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
{
bbidprofile = new BBIDProfile();
bbidprofile.addEventListener(BBIDEvent.SUCCESS, bbidOK);
bbidprofile.addEventListener(BBIDEvent.ERROR, bbidFailed);
}
private function bbidOK(event:BBIDEvent):void {
bbidprofile.getToken("BBIDv1", "urn:blackberry.com", gotBBIDToken, bbidFailed);
bbidprofile.getUserProperties(["username"], gotProps, bbidFailed);
}
private function gotProps(properties:Array, data:* = null):void {
for each(var prop:UserProperty in properties) {
log("Got user property: " + prop);
}
}
private function gotBBIDToken(token:String, tokenResponseParams:Array, data:* = null):void {
// Use token and tokenResponseParams (array of TokenParam) to make service call.
log("gotBBIDToken: " + token);
}
private function bbidFailed(message:String, data:* = null):void {
// Log error message and show the user an application error
log("Error: " + message);
}
private function log(msg:String):void
{
output.text += msg + "\n";
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:TextArea id="output" width="100%" height="100%" />
</s:WindowedApplication>
Note signing into the Simulator with your BlackBerry ID doesn’t seem to work for me, if it does work for you please let me know.