Google通讯录API批量删除问题

时间:2015-03-02 01:46:17

标签: c# google-api google-contacts google-data-api

我尝试使用联系人的批处理操作删除具有组的成员

但我无法删除干净,

我试图找到我的问题,可能是[etag]设置,

但我不知道如何在我的程序中使用[etag]。

任何人都可以帮助我吗?

    public void ClearMember()
    {
        List<Contact> requestFeed = new List<Contact>();
        ContactsRequest cr = CretificateRequest();
        Feed<Contact> fg = cr.GetContacts();
        Console.WriteLine(fg.TotalResults);
        int count = 0;
        foreach (Contact contact in fg.Entries)
        {
            try
            {
                string[] id = contact.Id.Split('/');
                Contact deleteContact = cr.Retrieve<Contact>(new Uri("https://www.google.com/m8/feeds/contacts/default/full/" + id[id.Length - 1]));
                deleteContact.BatchData = new GDataBatchEntryData(contact.Id, GDataBatchOperationType.delete);

                requestFeed.Add(deleteContact);
                count++;

                // Google Batch can not more then 100
                if (count != 0 && count % 95 == 0)
                {
                    Feed<Contact> responseFeedCT = cr.Batch(requestFeed, new Uri("https://www.google.com/m8/feeds/contacts/default/full/batch"), GDataBatchOperationType.delete);

                    // Check the status of each operation.
                    if (responseFeedCT != null)
                    {
                        foreach (Contact entry in responseFeedCT.Entries)
                        {
                            if (entry.BatchData.Status.Code != 200)
                            {
                                log.WriteContactsLog(entry.BatchData.Id + ": " + entry.BatchData.Status.Code + " (" + entry.BatchData.Status.Reason + ")");
                            }
                        }
                        requestFeed.Clear();
                    }
                    count = 0;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

        }

    }

        Feed<Contact> responseFeed = cr.Batch(requestFeed, new Uri("https://www.google.com/m8/feeds/contacts/default/full/batch"), GDataBatchOperationType.delete);

        // Check the status of each operation.
        if (responseFeed != null)
        {
            foreach (Contact entry in responseFeed.Entries)
            {
                if (entry.BatchData.Status.Code != 200)
                {
                    log.WriteContactsLog(entry.BatchData.Id + ": " + entry.BatchData.Status.Code + " (" + entry.BatchData.Status.Reason + ")");
                }
            }
        }
    }

0 个答案:

没有答案