AS3 code for retrieving contacts from Gmail

When I started learning Flex I developed a simple application which will retrieve contacts from Gmail accounts. I thought I should share it so that anyone can use it.

Application features

1.       Authenticates user with Gmail server

2.       Retrieve contacts from Gmail

3.       Parse the data returned by Gmail server and create typed objects

4.       Allows user to select contacts

5.       Once user is done selecting will throw an event with selected contacts as objects

Download Flex project from this URL:

Please feel free to Copy/Update/Delete this code 🙂

Any suggestions are most welcome 🙂


13 Responses to AS3 code for retrieving contacts from Gmail

  1. IanT says:

    That sounds really handy – thanks for publishing that, Sujit!

  2. Nice! I’m gonna look into this and report back soon. 🙂

    Thanks for the share.

  3. Thanks for sharing your code. I ran into a little problem, when i tried to retrieve my contacts, i had this error:
    Error: Unknown Property: ‘address’.
    at mx.collections::ListCollectionView/[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\]
    at com.adobe.contacts.contactsretrievers::GmailContactsRetriever/handleGetContactsFromServer()[C:\Users\fab\Documents\Flex Builder 3\ImportContacts\src\com\adobe\contacts\contactsretrievers\]
    at mx.rpc.http.mxml::HTTPService/[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\http\mxml\]
    at mx.rpc::AbstractInvoker/[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\]
    at mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\]
    at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\]
    at DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\]

    After a little debugging, it appears that the line
    contact.emailAddress = entries[i].email.address;( 100);
    was corrupted. Actually, the problem was that one of my gmail contacts have two emails associated. So the email Object doesn’t contain directly an address property but two objects with the address property.
    For a quick workaround, i just added ( 99):
    if (entries[i].email.length == undefined){
    contact.emailAddress = entries[i].email.address;
    It’s quite fast dirty and you should add another loop that would loop over the Objects inside “email” to add all the address but at least it worked and i could get my other contacts 😉

    PS: If you create a new Air 1.5 Project into Flex Builder and copy-paste this code, think about changing the application descriptor ImportContacts-app.xml and change the first line to <application xmlns=”″> or it won’t lauch 🙂

  4. BTW, you should add this plugin to your wordpress:
    it removes the curly quotes in the comments/texts so that it doesn’t mess the code when you copy/paste 😉


  5. Sujit Reddy G says:

    Hi Fabien,

    Thanks for the suggestions 🙂 I will find time to clean up the code and post it. Thanks again 🙂

  6. Haril says:

    How do you use this script?
    I am trying to copy all my contacts so I can create a mass mailing list.

    I have over 3,000 contacts in Gmail. HELP!

  7. Sujit Reddy G says:

    Hi Hari,

    getContacts() function in GmailContactsRetriever class is the one that should be invoked. In the ContactsSelectionComponent.mxml, you will find getContacts() function, which is invoking the GmailContactsRetriever.

    Hope this helps.

  8. Ben says:

    The authentication works (which is very cool), but I’m getting a 401 Authentication required fault thrown on the getContactsFromServer() function.

    Has Google changed some of their authentication requirements (very) recently that it might not work?

  9. Hi Ben,

    Is this Flex application running on a Flash Player on browser? In that case that might be because of Flash Player blocking Authenticate headers and Google not having crossdomain.xml as required

    Hope this helps.

  10. Manikandan says:

    hi sujit,
    Can you explain how to run this application,because it shows an error that (ContactsSelectionComponentEvent-not a compile time constant)

  11. Patrick says:

    This classes are made for a Desktop application.
    What are the changes I have to make to access gmail via a Flex web application?

  12. Hi Patrick,

    Gmail/Google server doesn’t have crossdomain policy file yet and so its not possible to get communicate with their servers from a web based Flash/Flex application.

  13. Senling says:

    To : Adobe Flex Tutorial
    Hi, I faced this issue
    Error: Unknown Property: ‘address’. and your workaround solved the issue. Is there any updated solution.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: