C# google contact api deleted contact

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 04:54:16

问题


currently I´m writing on a outlook plugin for syncing goolge contacts with outlook but I have to cover some special case:

When a contact gets deleted on google side, my application detects the missing contact and creates a new contact based on the contact info from the outlook one. Is there a way to get an event or history from google that tells me a user deleted this contact(s)?

Edit 1: Here is my code how I´m accessing the contacts (what is working FINE):

public GoogleAccessor()
{
    var parameters = new OAuth2Parameters()
    {
        ClientId = CLIENTID,
        ClientSecret = CLIENTSECRET,
        RedirectUri = REDIRECTURI,
        Scope = SCOPES
    };

    string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
    //An own webbrowser for processing the access tokens
    IAuthorizationCodeProvider authcodeProvider = new Presentation.BrowserAuthorizationCodeProvider(new Presentation.BrowserAuthentificatorVM());
    parameters.AccessCode = authcodeProvider.GetAuthorizationCode(url);

    if(parameters.AccessCode == null)
        throw new GoogleOAuthException("AccesCode returned 'null' and failed!");

    OAuthUtil.GetAccessToken(parameters);

    this._contactsRequest = new ContactsRequest(new RequestSettings(APPLICATIONNAME, parameters) {AutoPaging = true});
}
public IList<IContact> GetAllMappedContacts()
{
    Feed<Google.Contacts.Contact> f = _contactsRequest.GetContacts();
    this._feedUri = new Uri(f.AtomFeed.Feed);
    var photoList = new List<PhotoObject>();

    foreach (var entry in f.Entries)
    {
        var photoObject = GetContactPhoto(entry);
        if(photoObject != null)
            photoList.Add(photoObject);
    }
    _googleMapper = new GoogleMapper(f.Entries);
    return _googleMapper.MapToLocalContacts();;
}

回答1:


The thing about syncing in general is that syncing is normally meant to work in one direction.

Source Data -> Data Flow -> Received Data.

In this instance, Outlook is your source data and Google is your received data. All information needs to come from your source. Since this is an Outlook add-in you are creating my suggestion would be to add a button to your add-in ribbon. You can call the button whatever ever you like (maybe "dontSyncButton"), but it's purpose is going to be Categorization of your contact.

Make it so that that when a contact is selected and then the button is clicked, the contact is given a special categorization (perhaps "Dont Sync").

Now give some logic to your code that executes the sync, and have that logic decide whether to sync the contact. Also, give some logic to tell the program to delete the contact out of Google for you if the contacts contains the special category. Semi-Pseudo Code below:

 if(contact.Categories.ToString() == "Dont Sync")
 {
     //Don't Sync Contact
     If(googleContact.Exists())
     {
         //Delete contact from Google if it exist
         googleContact.Delete();
     } 
 }
 else
 {
     //Sync Contact
 }

It would be nice if Outlook had many modifiable properties that weren't visible to users, but since it does not this is really one of the best options I can think of. I do this to sync contacts from a shared Outlook folder to personal ones and it has worked well so far.

Hope this helps!



来源:https://stackoverflow.com/questions/27508640/c-sharp-google-contact-api-deleted-contact

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!