dav icon indicating copy to clipboard operation
dav copied to clipboard

Contacts from iCloud are filtered out

Open ide opened this issue 8 years ago • 7 comments

I looked into using dav to interact with my iCloud contacts so that I could programmatically add contacts to my phone. One of the first things I ran into was that dav returns an empty list of address books because it filters out all address books missing a displayname field. When I remove that filter call, I get back all of my iCloud contacts.

I'm not familiar with DAV and don't know the right fix right now but maybe someone who has experience with DAV knows how to address this.

Code:

var dav = require('dav');
var util = require('util');

var xhr = new dav.transport.Basic(
  new dav.Credentials({
    username: '[email protected]',
    password: 'hunter2',
  })
);

var client = new dav.Client(xhr);
client.createAccount({
  accountType: 'carddav',
  server: 'https://contacts.icloud.com',
  loadCollections: true,
  loadObjects: true,
}).then(account => {
  console.log(util.inspect(account.addressBooks, false, null));
}).catch(error => {
  console.error(error);
});

ide avatar Jun 13 '16 21:06 ide

@ide How exactly did you get this working? Using your example code I simply receive an empty array.

alexanderharm avatar Feb 11 '18 13:02 alexanderharm

IIRC the example code only reproduces the issue but it was from over a year ago.

ide avatar Feb 11 '18 13:02 ide

So you didn't manage to use this library to retrieve your contacts?

alexanderharm avatar Feb 11 '18 13:02 alexanderharm

From my original post it sounds like you could fork this library and get it working for this specific use case if that’s important. But I don’t think I used this library for my own project.

ide avatar Feb 11 '18 13:02 ide

Thanks.

alexanderharm avatar Feb 11 '18 13:02 alexanderharm

Tested with removing the filter and it still returns an empty list of addressBooks, so seems that it fails somewhere else too.

Bramzor avatar Apr 04 '19 16:04 Bramzor

This works for me with iCloud `addressBooks = responses.filter(function (res) {

        //return typeof res.props.displayname === 'string';

        return res.props.resourcetype.includes('addressbook');

}`

adamchasetaylor avatar Feb 07 '20 21:02 adamchasetaylor