Powered By
Showing posts with label Adobe AIR. Show all posts
Showing posts with label Adobe AIR. Show all posts

Google Account Authentication using ActionScript in Adobe AIR

View Comments
add to del.icio.us
saved by 0 users
Google Supports developers by providing lots of API for each and every service they provide. By using those APIs, developers can communicate with Google and get feeds from any of thier services by developing a web based application or a installable client application. Before starting to get feeds and post feeds to Google accounts from the application, the developers must get the user's Google account authenticated. To do that user credentials such as email id with password must be send to Google and if the credentials are correct then Google will send back a authorizing token using which developers can start getting feeds and process them.


To authenticate a user, use Google account API, that allow third party application to get limited access to a user's Google accounts for certain types of activities. The Google Authorization Service manages authentication, authorization, and access control to user accounts, subject to approval from the account holder. Google offers several account authorization APIs to accomodate different types of access. Google provides three types of access authorization methods. They are
Now let me explain authenticating with ClientLogin for installed desktop application and will explain others in the future post. I have used action script with flex SDK, but u can try with other technologies with minor changes in the code.

Download the Full Code
First send a http request to Google using HTTPService class with the user name and password by POST.

<mx:HTTPService id="Google"
url="https://www.google.com/accounts/ClientLogin"
method="POST"
contentType="application/x-www-form-urlencoded"
result="handleLoginPlain(event);"
fault="handleLoginFault(event);" >
<mx:request xmlns="">
<accountType>HOSTED_OR_GOOGLE</accountType>
<Email>UrEmail@gmail.com</Email>
<Passwd>UrPassword</Passwd>
<source>OrganizationName-AppName-Version</source>
<service>ServiceUrgoing2use</service>
</mx:request>
</mx:HTTPService>
Then scripts must be written to handle the result and failure.

<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;

[Bindable]
private var authString:String;

public function init():void {
Google.send();
}

private function handleLoginPlain(event:ResultEvent):void
{
var textindex:int;

trace("Event result "+event.result.toString());
authString = event.result.toString();
textindex = authString.search("Auth");
authString = authString.substring(textindex);
authString = authString.replace("Auth=","");
textindex = authString.length;
textindex = textindex - 1;
authString = authString.substring(0,textindex);

trace("Auth String "+authString);
}

public function handleLoginFault(event:FaultEvent):void
{
Alert.show("Login Error");
trace("Client Login Error Message"+event.message);
}
]]>
</mx:Script>
Explanation of the code:
First all the neccessary information for making a request are set in the HTTPService method. Dont forget to give a valid email and password in the class, otherwise you cannot get authorization. Then the request is send only in the scripting part in the init() function with will be called when application load completes by setting the tag "applicationComplete="init()"". The handlers are already set in the mx tag to handle the result event and failure event. A success response contains the authorization token, labeled "Auth", in the body of the response. Your application must reference this token in each request to the Google service for this user. Additional cookies, labeled "SID" and "LSID", are not currently active and should not be used. A failure response contains an error code and a URL to an error page that can be displayed to the user.

Check this links to get still more information from Google:
Read More

Steps to compile the source code of ShareFire

View Comments
add to del.icio.us
saved by 0 users
ShareFire is a simple but powerful news aggregator written in Adobe AIR. You can download the compiled version of ShareFire from ShareFire Home page. Using ShareFire you can share stories via AIM, Twitter, Facebook, MySpace, email and more with no copying and pasting, or dragging and dropping. And it even supports 16 different languages and mainly it is 100% open source. You can download the latest version of source for the project from Google Code. For doubts and discussion on this project you can find a busy active Google group.
Now let me explain you how to compile the code of ShareFire that is recently renamed as apprise.
  1. Download the code, either from Google Code or from Adobe. I prefer the second one, because the download from adobe contains all the dependencies with itself. If you download from google code dependencies must downloaded seperately and must be linked correcly else you will end up in mesh.
  2. Assuming you have downloaded the source from adobe, next step is to check the flex sdk version you got installed, if it is less than 3.3 then you must first upgrade it from opensource.abode.com. Unzip the downloaded SDK zip to any location you prefer.
  3. Now you must make the Flex IDE to recognize the new SDK installation. To do that open the IDE go to window->preferences->Installed flex SDK and click the add button. Now you will be asked for the location, browse to the location where you unzipped the newly downloaded SDK. Then finish by applying the changes.
  4. Now Create a new AIR project by File ->New ->Flex Project. Give a appropriate name to the project. Next look for the check box "Use default Location", if it is checked then uncheck it. Now browse to the location where you unzipped the project source downloaded from adobe. Choose the application type as "Desktop application(run in Adobe AIR)" and press Next and skip the next window where you be asked for the output folder, let it be default.
  5. In the next window before hitting finish, change the Main application file by pressing the browse button select the 'apprise.mxml' file shown in the popped up window. Now its done, the source is ready to compile.
  6. Now the IDE will throw you some errors, that's because apprise will support 16 languages for that supporting locale folders must be created in the SDK. For doing that open command prompt or a terminal window and navigate to the 'bin' folder of the newly installed SDK.
  7. Execute the following commands one after the other,
    • copylocale en_US de
    • copylocale en_US es
    • copylocale en_US fr
    • copylocale en_US it
    • copylocale en_US ja_JP
    • copylocale en_US ko
    • copylocale en_US pt
    • copylocale en_US ru
    • copylocale en_US zh_Hans
    • copylocale en_US zh_Hant
    1. Those commands will create the locale folder in the installed SDK. You can find those things in {SDK-HOME}\frameworks\locale.
    2. The last step in compiling the project is to add the compiler argument. To do the right click on the project name in the File navigator, choose properties. In the property window select flex compiler and in the text area labeling Additional compiler arguments, paste the following line
    -locale=de,en_US,es,fr,it,ja_JP,ko,pt,ru,zh_Hans,zh_Hant -source-path=locale/{locale}

    Apply the changes made by pressing the apply button and that's it. Run the program(ctrl+F11), you will
    see a window application running, thats the project.

    Enjoy editing the program and don't forget to comment on this post.
    Read More