2016-06-16 16 views
0

:파이썬 구글 연락처 API - 연락처 삭제 나는 하나의 접촉 삭제하는 방법을 볼 수있는 개발자 가이드를 읽기

def delete_contact(gd_client, contact_url): 
    # Retrieving the contact is required in order to get the Etag. 
    contact = gd_client.GetContact(contact_url) 

    try: 
    gd_client.Delete(contact) 
    except gdata.client.RequestError, e: 
    if e.status == 412: 
     # Etags mismatch: handle the exception. 
     pass 

모든 연락처를 삭제하는 방법이 있나요를? 그렇게 할 수있는 방법을 찾을 수 없습니다. 당신이 작업을 많이 수행하는 일괄 요청을 사용하는 경우

반복 처리는 각 연락처가 큰 배치

+0

api를 사용하여 모든 연락처를 가져올 수있는 경우 모든 연락처를 반복하여 delete_contact 함수에 전달할 수 있습니다. –

+0

1000 개의 연락처를 삭제하는 데 약 9 분이 걸립니다. 나는 더 빠른 해결책을 찾고 있었다 –

답변

0

에 대한 몇 분 정도 걸립니다. 서버가 단일 HTTP 요청으로 여러 작업을 수행하게 할 수 있습니다. 배치 요청은 한 번에 100 개의 작업으로 제한됩니다. 일괄 처리 작업에 대한 자세한 내용은 Google Data APIs Batch Processing documentation에서 확인할 수 있습니다.

delete all contacts contactsrequest.Batch 작업을 사용하십시오. 이 작업을 수행하려면 LIST<type>을 만들고 각 연락처 항목에 BatchData을 설정 한 다음 목록을 contactsrequest.Batch 작업에 전달합니다.

private void DeleteAllContacts() 
{ 
RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord); 
rs.AutoPaging = true // this will result in automatic paging for listing and deleting all contacts 
ContactsRequest cr = new ContactsRequest(rs); 
Feed<Contact> f = cr.GetContacts(); 
List<Contact> list = new List<Contact>(); 
int i=0; 
foreach (Contact c in f.Entries) 
{ 
c.BatchData = new GDataBatchEntryData(); 
c..BatchData.Id = i.ToString(); 
c.BatchData.Type = GDataBatchOperationType.delete; 
i++; 
list.Add(c); 
} 
cr.Batch(list, new Uri(f.AtomFeed.Batch), GDataBatchOperationType.insert); 
f = cr.GetContacts(); 
Assert.IsTrue(f.TotalResults == 0, "Feed should be empty now"); 
} 
+0

저에게 완벽한 솔루션이 될지도 모릅니다 - 파이썬 지원을위한 gdata 클라이언트는 일괄 처리입니까? 나는 그것을 거기에서 발견 할 수 없었다. –

+0

체크 [one] (https://developers.google.com/gdata/docs/client-libraries) – KENdi