Managing shared contacts i Google apps premier from Java

60 views
Skip to first unread message

Daniel

unread,
Jul 3, 2009, 7:34:30 AM7/3/09
to Google Contacts API
Hi,

I'm new to Google Apps. My primary language is Java.

Our company has to be able to have shared contacts of people not in
our domain. If I understand correctly it is possible to add/change/
delete shared contacts
through the API?

However I can't find any information on doing this from Java, is it
possible and if so could someone point me to an example?

Regards,

Daniel Johansson

Andre Roy

unread,
Jul 3, 2009, 7:59:10 AM7/3/09
to google-co...@googlegroups.com
Daniel wrote:
> Hi,
>
> I'm new to Google Apps. My primary language is Java.
>
Mine is English, but I also speak French and can carry on a conversation
in a bunch of other languages.... oh... COMPUTER LANGUAGE! Well, I did
my GoogleAPIs in C#....


> Our company has to be able to have shared contacts of people not in
> our domain. If I understand correctly it is possible to add/change/
> delete shared contacts
> through the API?
>

Yup. At least I did. :)

> However I can't find any information on doing this from Java, is it
> possible and if so could someone point me to an example?
>

With an Education or Premium Edition subscription it's pretty much just
the same as an individual's contacts:

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

but change the UIR to:

http://www.google.com/m8/feeds/contacts/YOUR_DOMAIN_HERE/full


At least I think that's what I did.

I did notice an interesting thing. When looking at the global contacts
through the API, you do not see the actual users you have, only the
contacts you have added with this. Minor thing, may be fixed in the
newer version of the API...

--
Andre -- Yes, there _are_ stupid questions.

Daniel

unread,
Jul 3, 2009, 8:36:14 AM7/3/09
to Google Contacts API
On 3 Juli, 13:59, Andre Roy <andrero...@gmail.com> wrote:
> Daniel wrote:
> > Hi,
>
> > I'm new to Google Apps. My primary language is Java.
>
> Mine is English, but I also speak French and can carry on a conversation
> in a bunch of other languages.... oh... COMPUTER LANGUAGE! Well, I did
> my GoogleAPIs in C#....
>
> > Our company has to be able to have shared contacts of people not in
> > our domain. If I understand correctly it is possible to add/change/
> > delete shared contacts
> > through the API?
>
> Yup. At least I did. :)
>
> > However I can't find any information on doing this from Java, is it
> > possible and if so could someone point me to an example?
>
> With an Education or Premium Edition subscription it's pretty much just
> the same as an individual's contacts:
>
> http://code.google.com/apis/contacts/docs/3.0/developers_guide_java.html
>
> but change the UIR to:
>
> http://www.google.com/m8/feeds/contacts/YOUR_DOMAIN_HERE/full
>
> At least I think that's what I did.

It seems to work, I did a listing of my shared contacks through the
API and found my recently added contact. However I can't find the
contact in the Contacts view and it doesn't show up when I start
typing an email address i gmail, normal?

Andre Roy

unread,
Jul 3, 2009, 8:41:46 AM7/3/09
to google-co...@googlegroups.com
Daniel wrote:
>>
>> At least I think that's what I did.
>
> It seems to work, I did a listing of my shared contacks through the
> API and found my recently added contact. However I can't find the
> contact in the Contacts view and it doesn't show up when I start
> typing an email address i gmail, normal?
>
Wait a day. It seems to take quite a while for them to actually show up
in the email interface. I have no idea why :(

Daniel

unread,
Jul 3, 2009, 8:52:57 AM7/3/09
to Google Contacts API
Thanks!

sting1999

unread,
Jul 17, 2009, 6:58:09 PM7/17/09
to Google Contacts API
Hi All,

Can someone help to confirm the steps to delete the Domain Shared
Contacts? Here is what I have done using Java client library:

1) Create a query to "http://www.google.com/m8/feeds/contacts/
{MY_DOMAIN}/full" and set a max results to be very large (e.g. 4,000)
to ensure to get all the shared contacts
2) Call the ContactsServer.getFeed() with the query and
ContactFeed.class to get the ContactFeed
3) Loop through the ContactFeed entries
4) Get the ContactEntry's editURL, e.g.
http://www.google.com/m8/feeds/contacts/{MY_DOMAIN}/full/dsfds3ksdfj03al39
5) Delete the shared contact by calling the ContactService.delete
(contactEntryEditURL)

I understand that it may take 24 hours to remove the shared contact so
that it won't appear in the auto-complete. I have waited more than 24
hours.

Is there way to verify the ContactEntry is deleted? I see there is a
has ContactEntry.hasDeleted() method, but I don't see any result
(seeing my deleted contact entry).

How to dump the ContactEntry out to a simple String to see the actual
its XML ATOM format?

Thanks,
Sting

On Jul 3, 5:52 am, Daniel <daniel.r.johans...@gmail.com> wrote:
> Thanks!
>
> On 3 Juli, 14:41, Andre Roy <andrero...@gmail.com> wrote:
>
> > Daniel wrote:
>
> > >> At least I think that's what I did.
>
> > > It seems to work, I did a listing of mysharedcontacks through the
> > > API and found my recently addedcontact. However I can't find the
> > >contactin the Contacts view and it doesn't show up when I start

Julian (Google)

unread,
Jul 20, 2009, 8:21:22 AM7/20/09
to Google Contacts API
Hi Sting,

What error are you getting when you try to delete the Shared Contact?
Do you still see the Shared Contact on the feed?

Also, please double check that you are not trying to delete a Profile
(a domain's user), information about domain's users now shows in auto-
complete.

In case you need it, you can find more information about the Profile
API here:
http://code.google.com/apis/apps/profiles/developers_guide_protocol.html

Cheers,
Julian.

On Jul 17, 11:58 pm, sting1999 <oraps1...@gmail.com> wrote:
> Hi All,
>
> Can someone help to confirm the steps to delete the DomainSharedContacts?  Here is what I have done usingJavaclient library:
>
> 1) Create a query to "http://www.google.com/m8/feeds/contacts/
> {MY_DOMAIN}/full" and set a max results to be very large (e.g. 4,000)
> to ensure to get all thesharedcontacts
> 2) Call the  ContactsServer.getFeed() with the query and
> ContactFeed.class to get the ContactFeed
> 3) Loop through the ContactFeed entries
> 4) Get the ContactEntry's editURL, e.g.http://www.google.com/m8/feeds/contacts/{MY_DOMAIN}/full/dsfds3ksdfj03al39
> 5) Delete thesharedcontact by calling the ContactService.delete
> (contactEntryEditURL)
>
> I understand that it may take 24 hours to remove thesharedcontact so
> that it won't appear in the auto-complete.  I have waited more than 24
> hours.
>
> Is there way to verify the ContactEntry is deleted?  I see there is a
> has ContactEntry.hasDeleted() method, but I don't see any result
> (seeing my deleted contact entry).
>
> How to dump the ContactEntry out to a simple String to see the actual
> its XML ATOM format?
>
> Thanks,
> Sting
>
> On Jul 3, 5:52 am, Daniel <daniel.r.johans...@gmail.com> wrote:
>
> > Thanks!
>
> > On 3 Juli, 14:41, Andre Roy <andrero...@gmail.com> wrote:
>
> > > Daniel wrote:
>
> > > >> At least I think that's what I did.
>
> > > > It seems to work, I did a listing of mysharedcontacks through the
> > > > API and found my recently addedcontact. However I can't find the
> > > >contactin theContactsview and it doesn't show up when I start

sting1999

unread,
Jul 20, 2009, 3:51:28 PM7/20/09
to Google Contacts API
Hi Julian,

I got this error when trying to delete the shared contact:
com.google.gdata.util.ServiceForbiddenException: Forbidden
If-Match or If-None-Match header required

Here is my step to delete the shared contact:
1) ContactsService.delete(url); (the contact edit URL that is
retrieved from call the ContactsService.getFeed(query,
ContactFeed.class)

The shared contact that I tried to delete is a Google Apps Group,
which I was able to add to the Shared Contact and see the auto-
completion in the CC, To, Bcc fields.

Please let me know if the right way to delete the shared contact of a
Google Apps Group. Or, is it even correct to use the Shared Contact
for the Google Apps Group? I am not sure if the Profile API apply to
my case (i.e. I just want to add the Google Apps Group so that it will
appear in the auto-completion).

Thank you for your help.

Regards,
Sting

Julian (Google)

unread,
Jul 21, 2009, 9:06:45 AM7/21/09
to Google Contacts API
Hi Sting,

What version of the Java Client library are you using? I think that
the latest version does not required to include the ETag information.
You can always add the "If-Match: *" header if needed. Also, try to
use the entry ID instead of the Edit URL: entry.getId()

The Shared Contacts sounds like a good way to add a Group's email
address as a contact, because this information is not included in
Profiles.

Cheers,
Julian.

On Jul 20, 8:51 pm, sting1999 <oraps1...@gmail.com> wrote:
> Hi Julian,
>
> I got this error when trying to delete thesharedcontact:
> com.google.gdata.util.ServiceForbiddenException: Forbidden
> If-Match or If-None-Match header required
>
> Here is my step to delete thesharedcontact:
> 1) ContactsService.delete(url);  (the contact edit URL that is
> retrieved from call the ContactsService.getFeed(query,
> ContactFeed.class)
>
> Thesharedcontact that I tried to delete is aGoogleAppsGroup,
> which I was able to add to theSharedContact and see the auto-
> completion in the CC, To, Bcc fields.
>
> Please let me know if the right way to delete thesharedcontact of aGoogleAppsGroup.  Or, is it even correct to use theSharedContact
> for theGoogleAppsGroup?  I am not sure if the Profile API apply to
> my case (i.e. I just want to add theGoogleAppsGroup so that it will
> appear in the auto-completion).
>
> Thank you for your help.
>
> Regards,
> Sting
>
> On Jul 20, 5:21 am, "Julian (Google)" <j...@google.com> wrote:
>
> > Hi Sting,
>
> > What error are you getting when you try to delete theSharedContact?
> > Do you still see theSharedContact on the feed?

sting1999

unread,
Jul 21, 2009, 10:40:22 AM7/21/09
to Google Contacts API
Hi Julian,

I am using Java Client Library 1.34.0. I am able to get the auto-
completion after creating the Group's email address as a contact via
the Shared Contacts API. I will need to be able to delete the Shared
Contacts before adding all the Group's email address as a contact.

How would add the "If-Match:*" header and entry ID using the Java
Client Library?

Thanks,
Sting

sting1999

unread,
Jul 21, 2009, 9:49:01 PM7/21/09
to Google Contacts API
Hi Julian,

For the ContactService.delete() operation, I have tried all the
different URL values, such as the following:
1) <id> value, e.g. http://www.google.com/m8/feeds/contacts/{MY_DOMAIN}/base/19a72320f4e0e64
2) edit link value, e.g. http://www.google.com/m8/feeds/contacts/{MY_DOMAIN}/full/19a72320f4e0e64/1247610287731000

Using the id value give me this error:
com.google.gdata.util.ServiceForbiddenException: Forbidden
If-Match or If-None-Match header required

Uisng the edit link give me this error:
com.google.gdata.util.InvalidEntryException: Bad Request
Unexpected resource version ID

It seems like the id link is more correct. How would you add the "If-
Match:*" header using the Java Client Library?

Thanks,
Sting

Julian (Google)

unread,
Jul 22, 2009, 6:24:01 AM7/22/09
to Google Contacts API
Hi,

The easiest way to delete a contact is to use the delete method from
the ContactEntry itself: contactEntry.delete()

However, in your case, when using the sevice directly you need to
specify the ETag to match the stored entry: contactsService.delete
(resourceUri, etag)

Cheers,
Julian.

On Jul 22, 2:49 am, sting1999 <oraps1...@gmail.com> wrote:
> Hi Julian,
>
> For the ContactService.delete() operation, I have tried all the
> different URL values, such as the following:
> 1) <id> value, e.g.http://www.google.com/m8/feeds/contacts/{MY_DOMAIN}/base/19a72320f4e0e64
> 2) edit link value, e.g.http://www.google.com/m8/feeds/contacts/{MY_DOMAIN}/full/19a72320f4e0e64/1247610287731000

sting1999

unread,
Jul 23, 2009, 6:25:10 PM7/23/09
to Google Contacts API
Hi Julian,

Thank you for your help. Your recommendation is working! I do not
see the deleted contact in the auto-completion.

I am still not very clear on the different contact APIs (contact,
profile, and shared contact). Can you clarify for each APIs for
domain users, non-domain users, and apps group? Which APIs should be
used to add more extended properties for the contact?

Regards,
Sting
Reply all
Reply to author
Forward
0 new messages