Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Pages: 1
Bonjour à tous, voila je souhaite récupérer une liste de contact Gmail, j'ai donc réaliser le code suivant, malheureusement (bien entendu...)il ne fonctionne pas, j'obtiens l'erreur suivante :
Exception information: Message: Expected response code 200, got 403 Cannot request contacts belonging to another domain (blabla). Error 403 Stack trace: #0 C:\wamp\www\quickstart\library\Zend\Gdata.php(219): Zend_Gdata_App->performHttpRequest('GET', 'http://www.goog...', Array, NULL, NULL, NULL) #1 C:\wamp\www\quickstart\library\Zend\Gdata\App.php(861): Zend_Gdata->performHttpRequest('GET', 'http://www.goog...', Array) #2 C:\wamp\www\quickstart\library\Zend\Gdata\App.php(754): Zend_Gdata_App->get('http://www.goog...', NULL) #3 C:\wamp\www\quickstart\library\Zend\Gdata\App.php(205): Zend_Gdata_App->importUrl('http://www.goog...', 'Zend_Gdata_Feed', NULL) #4 C:\wamp\www\quickstart\library\Zend\Gdata.php(162): Zend_Gdata_App->getFeed('http://www.goog...', 'Zend_Gdata_Feed') #5 C:\wamp\www\quickstart\library\My\ContactsGetter\Modules\Gmail.php(38): Zend_Gdata->getFeed(Object(Zend_Gdata_Query)) #6 C:\wamp\www\quickstart\application\controllers\IndexController.php(17): My_ContactsGetter_Modules_Gmail->getAllContacts('***', '***') #7 C:\wamp\www\quickstart\library\Zend\Controller\Action.php(513): IndexController->indexAction() #8 C:\wamp\www\quickstart\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('indexAction') #9 C:\wamp\www\quickstart\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #10 C:\wamp\www\quickstart\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() #11 C:\wamp\www\quickstart\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #12 C:\wamp\www\quickstart\public\index.php(28): Zend_Application->run() #13 {main} Request Parameters: array ( 'controller' => 'index', 'action' => 'index', 'module' => 'default', )
Voici le code de ma fonction :
public function getAllContacts($login, $password) { $client = Zend_Gdata_ClientLogin::getHttpClient($login,$password,"cp"); $client->setConfig(array('timeout' => 30)); $response = $client->getLastResponse()->getStatus(); // Si la requete à abouti (oui si response=200) if ($response == 200) { $token = $client->getClientLoginToken(); $gdata = new Zend_Gdata($client); $query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/'.$login.'/full'); $query->setMaxResults(1000); $feed = $gdata->getFeed($query); // $xml = new SimpleXMLElement($feed->getXML()); $entries = $xml->children('http://www.w3.org/2005/Atom'); // Pour chaque contact (entry) foreach ($entries->entry as $entry ) { $defaults = $entry->children('http://schemas.google.com/g/2005'); $nom = $entry->title; $mail = $defaults->email->attributes()->address; $URi = urlencode($entry->link[1]->attributes()); $img = ''; $contacts[] = new Contact($nom, $mail, $img); // on crée un contact } return $contacts; } }
Mon index :
<?php // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('My_'); // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap() ->run();
Mon appel à ma fonction dans le controller :
public function indexAction() { // action body // titre de la page $this->view->title = "ShAdY! Contacts"; $gmail = new My_ContactsGetter_Modules_Gmail(); $contacts = $gmail->getAllContacts("login", "mdp"); }
Si quelqu'un pouvait m'indiquer mes erreurs je lui en serait très reconnaissant:ccool:
Merci à tous d'avance:aie:
Dernière modification par shadypierre (12-04-2010 15:22:46)
Hors ligne
Autant pour moi, j'ai trouvé l'erreur...Ma fonction n'avait aucune erreur c'était mon appel à la fonction qui été mauvais, j'utilisé un login sans le "@gmail.com" à la fin
Erreur bête qui m'as fait perdre un temps fou
Merci quand même!
Hors ligne
Pages: 1