Я использую этот скрипт для удаления контактов из GMAIL, и иногда он работает, но он не удаляет каждый пример контакта, я пытаюсь удалить «ADRIANA CALI», этот контакт находится в группе под названием «modelos», но он не будет удалять это имя … есть идеи, пожалуйста?
<?php
// load Zend Gdata libraries
//require 'init_autoloader.php';
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Feed');
// set credentials for ClientLogin authentication
$user = "[email protected]";
$pass = "samplepassword";
//contact name to delete
$contact_name = 'ADRIANA CALI';
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'cl');
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
} catch (Zend_Gdata_App_AuthException $ae) {
echo 'Problem authenticating: ' . $ae->exception() . "\n";
}
try {
// perform login and set protocol version to 3.0
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'cp');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$query = new Zend_Gdata_Query('https://www.google.com/m8/feeds/contacts/default/full');
$feed = $gdata->getFeed($query);
$contacts=array();;
foreach($feed as $entry){
$name = (string) $entry->title;
if(strcasecmp($name,$contact_name)==0) {
//echo '<xmp>';print_r($entry);echo '</xmp>';
$id = substr((string) $entry->id,(strpos((string) $entry->id,'base')+5));
$contacts[] = array('id'=>$id,'name'=>$name);
echo $entry->id;
}
//$xml = simplexml_load_string($entry->getXML());
//$obj = new stdClass;echo $entry->title."<br/>";
//$obj->name = (string) $entry->title;
//$editLink = $entry->getEditLink()->href;
//echo $editLink.'-66<br>';
//$extra_header = array('If-Match'=>'*');
//$entry->delete();
}
?>
<h2>Deleting One Contact</h2>
<div><?php echo count($contacts); ?> contact(s) found for deletion under Contact "<?php echo $contact_name; ?>".</div>
<?php
foreach($contacts as $contact){
$deleteLink = 'https://www.google.com/m8/feeds/contacts/default/full/'.$contact['id'];
//$deleteLink = ' http://www.google.com/m8/feeds/contacts/userEmail/base/contactID';
//echo $deleteLink.'<br>';
//$deleteLink = $contact['id'];
//$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'cp');
$client->setHeaders(array('If-Match'=>'*','If-None-Match'=>'anything'));
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
// delete entry
$gdata->delete($deleteLink);
}
} catch (Exception $e) {
die('ERROR 71:' . $e->getMessage());
}
?>
<?php
// display results
foreach ($contacts as $contact) {
?>
<div class="entry">
<div class="name"><?php echo (!empty($contact['name'])) ? $contact['name'] : 'Name not available' . ' deleted!'; ?></div>
</div>
<?php
}
?>
Это было связано с тем, что был достигнут максимальный контакт, и запрос больше не обрабатывался. Теперь я установил максимальный предел в 1000
<?php
// load Zend Gdata libraries
//require 'init_autoloader.php';
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Feed');
// set credentials for ClientLogin authentication
$user = "[email protected]";
$pass = "sample password";
//contact name to delete
$contact_name = 'ADRIANA CALI';
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'cl');
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
} catch (Zend_Gdata_App_AuthException $ae) {
echo 'Problem authenticating: ' . $ae->exception() . "\n";
}
try {
// perform login and set protocol version to 3.0
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'cp');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$query = new Zend_Gdata_Query('https://www.google.com/m8/feeds/contacts/default/full?max-results=1000');
$feed = $gdata->getFeed($query);
$contacts=array();;
foreach($feed as $entry){
$name = (string) $entry->title;
if(strcasecmp($name,$contact_name)==0) {
//echo '<xmp>';print_r($entry);echo '</xmp>';
$id = substr((string) $entry->id,(strpos((string) $entry->id,'base')+5));
$contacts[] = array('id'=>$id,'name'=>$name);
//echo '<br>m-'.$name.'-'.$entry->id;
}
//$xml = simplexml_load_string($entry->getXML());
//$obj = new stdClass;echo $entry->title."<br/>";
//$obj->name = (string) $entry->title;
//$editLink = $entry->getEditLink()->href;
//echo $editLink.'-66<br>';
//$extra_header = array('If-Match'=>'*');
//$entry->delete();
}
?>
<h2>Deleting One Contact</h2>
<div><?php echo count($contacts); ?> contact(s) found for deletion under Contact "<?php echo $contact_name; ?>".</div>
<?php
foreach($contacts as $contact){
$deleteLink = 'https://www.google.com/m8/feeds/contacts/default/full/'.$contact['id'];
//$deleteLink = ' http://www.google.com/m8/feeds/contacts/userEmail/base/contactID';
//echo $deleteLink.'<br>';
//$deleteLink = $contact['id'];
//$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'cp');
$client->setHeaders(array('If-Match'=>'*','If-None-Match'=>'anything'));
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
// delete entry
$gdata->delete($deleteLink);
}
} catch (Exception $e) {
die('ERROR 71:' . $e->getMessage());
}
?>
<?php
// display results
foreach ($contacts as $contact) {
?>
<div class="entry">
<div class="name"><?php echo (!empty($contact['name'])) ? $contact['name'] : 'Name not available' . ' deleted!'; ?></div>
</div>
<?php
}
?>
Других решений пока нет …