2016-06-16 16 views
0

PythonのGoogleの連絡先の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

それは私のための完璧な解決策かもしれない - pythonサポートバッチのgdataクライアントですか?私はそこにそれを見つけることができませんでした。 –

+0

これをチェックする[1](https://developers.google.com/gdata/docs/client-libraries) – KENdi

関連する問題