My favorites | Sign in
Project Logo
                
Search
for
Updated Jan 11, 2008 by mdw1980
Labels: Featured
Resources  
Articles, examples, and other various resources

Basic Authentication and Blog List Retrieval Example

The following example illustrates how to use the AccountsService class to authenticate a Google account/user for the Blogger Data API.

package
{
    import net.nobien.webapis.google.accounts.AccountsService;
    import net.nobien.webapis.google.accounts.AuthError;
    import net.nobien.webapis.google.accounts.AuthResult;
    import net.nobien.webapis.google.blogger.BloggerService;
    import net.nobien.webapis.google.events.AccountsEvent;
    import net.nobien.webapis.google.events.BloggerEvent;
    
    public class AccountsServiceExample
    {
        private var accountsService:AccountsService;
        private var bloggerService:BloggerService;
        
        public function AccountsServiceExample()
        {
            bloggerService = new BloggerService();
            bloggerService.addEventListener( BloggerEvent.BLOG_LIST_RETURNED, handleBlogListReturned );
            
            accountsService = new AccountsService();
            accountsService.addEventListener( AccountsEvent.AUTH_FAILURE, handleAuthFailure );
            accountsService.addEventListener( AccountsEvent.AUTH_GET_TOKEN, handleAuthGetToken );
            accountsService.clientLogin.authenticate( "username", "password", BloggerService.SERVICE_NAME, "companyName-applicationName-versionID" );
        }
        
        private function handleAuthGetToken( event:AccountsEvent ):void
        {
            var authResult:AuthResult = AuthResult( event.data );
            trace( "handleAuthGetToken > event.data:" + authResult );
            
            bloggerService.authHeader = accountsService.authHeader;
            bloggerService.getBlogs();
        }
        
        private function handleAuthFailure( event:AccountsEvent ):void
        {
            var authError:AuthError = AuthError( event.data );
            trace( "handleAuthFailure > event.data:" + authError );
        }
        
        private function handleBlogListReturned( event:BloggerEvent ):void
        {
            var blogList:Array = event.data as Array;
            trace( "handleBlogListReturned > event.data:" + blogList );
        }
    }
}


Sign in to add a comment
Hosted by Google Code