Deleting contacts from a Google Apps Domain user account fails on Linux

153 Views Asked by At

Using the google-gdata client libraries I'm able to add contacs to a Google/GMail account
but when I try to delete them I get two different results based on the type of account.

When the target account is a pure GMail account, I can delete contacts but it does not delete
all contacts in one go. Sometimes it will return a few, sometimes up to 25, even though I'm checking
if there are more contacts and looping over them.

When the target account is a Google Apps account I simply get a timeout (after about 2 minutes)
Note that even for a Google Apps account I can add contacts.

let service = new ContactsService("ContactSync")
service.setUserCredentials(username, password)

let token = service.QueryClientLoginToken()
service.SetAuthenticationToken(token)

let uri = ContactsQuery.CreateContactsUri("default")
let query = new ContactsQuery(uri)

let rec DeleteAllGoogleContacts (query : ContactsQuery) =
    let feed = service.Query(query) : ContactsFeed

    feed.Entries 
    |> List.ofSeq
    |> List.iter(fun f -> f.Delete())

    match feed.NextChunk with
    | x when String.IsNullOrWhiteSpace(x) -> ()
    | _ -> DeleteAllGoogleContacts(new ContactsQuery(feed.NextChunk)) 

DeleteAllGoogleContacts(query)

The error for a Google Apps account is (email changed for privacy):

Google.GData.Client.GDataRequestException: Execution of request failed: https://www.google.com/m8/feeds/contacts/[email protected]/full/22280c0f9f627f ---> System.Net.WebException: The request timed out at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in :0 at System.Net.HttpWebRequest.GetResponse () [0x00000] in :0 at Google.GData.Client.GDataRequest.Execute () [0x00000] in :0 --- End of inner exception stack trace --- at Google.GData.Client.GDataRequest.Execute () [0x00000] in :0 at Google.GData.Client.GDataGAuthRequest.Execute (Int32 retryCounter) [0x00000] in :0

When DeleteAllGoogleContacts is first called, it will succeed in getting the feed
and the number of entries is smaller or equal to 25. The timeout occurs upon calling f.Delete()

Please note that, as far as I am currently aware, I cannot use OAuth here because this will run on a headless server with no user interaction.

Update:

I found that there's another way to retrieve the contacts

let Delete() =
    let requestSettings = new RequestSettings("ContactSync", username, password)
    requestSettings.AutoPaging <- true

    let contactsRequest = new ContactsRequest(requestSettings)

    let feed = contactsRequest.GetContacts() : Feed<Contact>
    feed.Entries
    |> List.ofSeq
    |> List.iter(fun f -> contactsRequest.Delete(f))

This retrieves all contacts in one go, but I still get a timeout upon Delete()

Update 2:

This may actually be firewall related as I can get it to work from another network. If so, I'll delete the question as it is not relevant.

Update 3:

It does not seem to be caused by a firewall.
When running this on Windows with .NET everything works as expected.
When running this on Linux with the latest Mono and FSharp compiled from source,
we get the timeout exception.

My only guess here is that it's got something to do with the SSL certificates.
For example, if you want to access the GMail SMTP on Linux you have to issue the following commands:

mozroots --import --ask-remove
certmgr --ssl smtps://smtp.gmail.com:465

Otherwise it will not work. Perhaps I have to do something similar for the GData API's?

Update 4:

Looking at the endpoints for Update() and Delete(), you can see they are one and the same

https://www.google.com/m8/feeds/contacts/userEmail/full/{contactId}

The only difference is the HTTP verb being used: PUT vs UPDATE, and I confirmed
that Update() does work on both platforms for both targets (Windows/Linux), (GMail, Google Apps)

The image below shows the 4 different scenarios for Delete():

enter image description here

0

There are 0 best solutions below

Related Questions in F#