0

I am creating shared contacts in google, it creates the contact, but I can't see the contacts in the directory in google contacts.

I have looked for answers and found this probably closest.. but I can't seem to get it right...

Here is some code:

    string s = "https://www.google.com/m8/feeds";
string targetUri = @"https://www.google.com/m8/feeds/contacts/mycompany.com/full";          
    string serviceAccountEmail = "123456789012-xxxx1x1xx11x1xxxxxxx11xxxx1xxx11@developer.gserviceaccount.com";
    string serviceClientId = "123456789012-xxxx1x1xx11x1xxxxxxx11xxxx1xxx11.apps.googleusercontent.com";
    X509Certificate2 certificate = new X509Certificate2(@"C:\All\mygcertificate-1xx1xxx1xx11.p12", "notasecret", X509KeyStorageFlags.Exportable);

    ServiceAccountCredential credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
    {
        Scopes = new[]
    {
        "http://www.google.com/m8/feeds/contacts/"
    },
        User = "my.user@mycompany.com"
    }.FromCertificate(certificate));


    string AuthenticationToken1 = string.Empty;
    if (credential.RequestAccessTokenAsync(CancellationToken.None).Result)
    {
        AuthenticationToken1 = credential.Token.AccessToken;
    }

    Service service = new Service(s, serviceClientId);

     GAuthSubRequestFactory factory = new GAuthSubRequestFactory(s, serviceClientId);
    factory.Token = AuthenticationToken1;
    service.RequestFactory = factory;


    Contact ct = new Contact();
    ct.Name = new Google.GData.Extensions.Name() { GivenName = "Ron", FamilyName = "Swanson", FullName = "Ron Swanson" };
    ct.Emails.Add(new Google.GData.Extensions.EMail("Ron.Swanson@someclient.com", @"http://schemas.google.com/g/2005#work") { Primary = true });
    ct.Phonenumbers.Add(new Google.GData.Extensions.PhoneNumber("2345555522") { Rel = @"http://schemas.google.com/g/2005#work", Primary = true});
    AtomCategory atc = new AtomCategory();
    atc.Term = @"http://schemas.google.com/contact/2008#contact";
    atc.Scheme = @"http://schemas.google.com/g/2005#kind";
    ct.Categories.Add(atc);


    var atomentrytoinsert = ct.AtomEntry;

    var result = service.Insert(new Uri(targetUri), atomentrytoinsert);

    //Stream getresult = service.Query(new Uri(targetUri)); //this read actually gets the records i inserted...

If i run that last commented out line, i can see the entries I created ... but when I go to google contacts and click directory - They are not there. Also not on autocomplete when I compose email... Am I missing a attribute somewhere.

I have left the entries over 24 hours (I created them on Friday).

Would appreciate any input.

Community
  • 1
  • 1
Cranzy
  • 49
  • 1
  • 8

1 Answers1

0

I tryed the sharedcontact API yesterday, the new contacts were not visible in directory.

But this morning the autocomplete has suggested the new contacts! To make them visible in the directory I had to open the Admin google Console->google apps-> contacts -> advanced settings and checked the " shows both the profiles of the domain is the Domain Shared Contacts"

It worked immediately for me, I hope help you!

uffa14
  • 155
  • 1
  • 8