NAME

WWW::Google::Contacts - Google Contacts Data API

CURRENTLY NOT WORKING

This module is currently not working. Some time back, Google obsoleted the authentication method used by this module.

Patches for updating how authentication is handled are more than welcome!

SYNOPSIS

    use WWW::Google::Contacts;

    my $google = WWW::Google::Contacts->new(
        username => "your.username",
        password => "your.password",
        protocol => "https",
    );

    # Create a new contact
    my $contact = $google->new_contact;
    $contact->full_name("Emmett Brown");
    $contact->name_prefix("Dr");
    $contact->email('doctor@timetravel.org');
    $contact->hobby("Time travel");
    $contact->jot([ "Went back in time", "Went forward in time", "Became blacksmith" ]),
    $contact->create;  # save it to the server

    # Now search for the given name, and read the jots
    my @contacts = $google->contacts->search({ given_name => "Emmett" });
    foreach my $c ( @contacts ) {
        print "Got the following jots about the good doctor\n";
        foreach my $jot ( @{ $c->jot } ) {
            print "Jot: " . $jot->value . "\n";
        }
        print "And now he goes back to the future\n";
        $c->delete;
    }

    # Print the names of all groups
    my $groups = $google->groups;
    while ( my $group = $groups->next ) {
        print "Title = " . $group->title . "\n";
    }

    # Add the contact to existing group 'Movie stars' and to a new group 'Back to the future'
    my $new_group = $google->new_group({ title => "Back to the future" });
    $new_group->create;  # create on server

    my @groups = $google->groups->search({ title => "Movie stars" });
    my $movie_stars_group = shift @groups;

    $contact->add_group_membership( $new_group );
    $contact->add_group_membership( $movie_stars_group );
    $contact->update;

DESCRIPTION

This module implements 'Google Contacts Data API' according http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html

NOTE This new interface is still quite untested. Please report any bugs.

CONSTRUCTOR

new( username => .., password => .. , protocol => ..)

username and password are required arguments and must be valid Google credentials. If you do not have a Google account you can create one at https://www.google.com/accounts/NewAccount.

protocol defaults to http, but can optionally be set to https.

METHODS

$google->new_contact

Returns a new empty WWW::Google::Contacts::Contact object.

$google->contact( $id )

Given a valid contact ID, returns a WWW::Google::Contacts::Contact object populated with contact data from Google.

$google->contacts

Returns a WWW::Google::Contacts::ContactList object which can be used to iterate over all your contacts.

$google->new_group

Returns a new WWW::Google::Contacts::Group object.

$google->group( $id )

Given a valid group ID, returns a WWW::Google::Contacts::Group object populated with group data from Google.

$google->groups

Returns a WWW::Google::Contacts::GroupList object which can be used to iterate over all your groups.

DEPRECATED METHODS

The old module interface is still available, but its use is discouraged. It will eventually be removed from the module.

  • new/login

        my $gcontacts = WWW::Google::Contacts->new();
        $gcontacts->login('fayland@gmail.com', 'pass') or die 'login failed';
  • create_contact

        $gcontacts->create_contact( {
            givenName => 'FayTestG',
            familyName => 'FayTestF',
            fullName   => 'Fayland Lam',
            Notes     => 'just a note',
            primaryMail => 'primary@example.com',
            displayName => 'FayTest Dis',
            secondaryMail => 'secndary@test.com', # optional
        } );

    return 1 if created

  • get_contacts

        my @contacts = $gcontacts->get_contacts;
        my @contacts = $gcontacts->get_contacts( {
            group => 'thin', # default to 'full'
        } )
        my @contacts = $gcontacts->get_contacts( {
            updated-min => '2007-03-16T00:00:00',
            start-index => 10,
            max-results => 99, # default as 9999
        } );

    get contacts from this account.

    group refers http://code.google.com/apis/contacts/docs/2.0/reference.html#Projections

    start-index, max_results etc refer http://code.google.com/apis/contacts/docs/2.0/reference.html#Parameters

  • get_contact($id)

        my $contact = $gcontacts->get_contact('http://www.google.com/m8/feeds/contacts/account%40gmail.com/base/1');

    get a contact by id

  • update_contact

        my $status = $gcontacts->update_contact('http://www.google.com/m8/feeds/contacts/account%40gmail.com/base/123623e48cb4e70a', {
            givenName => 'FayTestG2',
            familyName => 'FayTestF2',
            fullName   => 'Fayland Lam2',
            Notes     => 'just a note2',
            primaryMail => 'primary@example2.com',
            displayName => 'FayTest2 Dis',
            secondaryMail => 'secndary@test62.com', # optional
        } );

    update a contact

  • delete_contact($id)

        my $status = $gcontacts->delete_contact('http://www.google.com/m8/feeds/contacts/account%40gmail.com/base/1');

    The id is from get_contacts.

  • create_group

        my $status = $gcontacts->create_group( { title => 'Test Group' } );

    Create a new group

  • get_groups

        my @groups = $gcontacts->get_groups;
        my @groups = $gcontacts->get_groups( {
            updated-min => '2007-03-16T00:00:00',
            start-index => 10,
            max-results => 99, # default as 9999
        } );

    Get all groups.

  • get_group($id)

        my $group = $gcontacts->get_group('http://www.google.com/m8/feeds/groups/account%40gmail.com/base/6e744e7d0a4b398c');

    get a group by id

  • update_group($id, { title => $title })

        my $status = $gcontacts->update_group( 'http://www.google.com/m8/feeds/groups/account%40gmail.com/base/6e744e7d0a4b398c', { title => 'New Test Group 66' } );

    Update a group

  • delete_group

        my $status = $gcontacts->delete_contact('http://www.google.com/m8/feeds/groups/account%40gmail.com/base/6e744e7d0a4b398c');

SEE ALSO

WWW::Google::Contacts::Contact

WWW::Google::Contacts::ContactList

WWW::Google::Contacts::Group

WWW::Google::Contacts::GroupList

http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html

ACKNOWLEDGEMENTS

Fayland Lam - who wrote the first version of this module

John Clyde - who shared his code about Contacts API with Fayland

TODO

More POD
Unit tests. Very lame right now
Images
Fix bugs :)

AUTHOR

  Magnus Erixzon <magnus@erixzon.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Magnus Erixzon.

This is free software; you can redistribute it and/or modify it under the same terms as perl itself.