2011-02-16 2 views
1

this 자습서는 PHP를 사용하여 Google 주소록을 검색하는 방법에 대해 많이 언급했습니다. Zend를 설치하고 제공된 코드 예제를 사용하기 만하면됩니다.Google 주소록 검색 Zend 사용

저는 젠드를 설치했습니다 (제 생각 엔). 그런 다음 튜토리얼에서 아래의 코드를 시도하고 [email protected]을 내 Gmail 주소로 바꾸고 guessme을 내 Gmail 비밀번호로 바꿨다. 아래 코드가 모든 Gmail 연락처를 반환한다고 생각했다. 그러나 빈 화면 만 반환합니다.

젠드를 올바르게 설치하지 않았다는 뜻입니까?

<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    <head> 
    <title>Listing contacts</title> 
    <style> 
    body { 
     font-family: Verdana;  
    } 
    div.name { 
     color: red; 
     text-decoration: none; 
     font-weight: bolder; 
    } 
    div.entry { 
     display: inline; 
     float: left; 
     width: 400px; 
     height: 150px; 
     border: 2px solid; 
     margin: 10px; 
     padding: 5px; 
    } 
    td { 
     vertical-align: top; 
    } 
    </style>  
    </head> 
    <body> 

    <?php 
    // load Zend Gdata libraries 
    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 = "guessme"; 

    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); 

     // perform query and get result feed 
     $query = new Zend_Gdata_Query(
     'http://www.google.com/m8/feeds/contacts/default/full'); 
     $feed = $gdata->getFeed($query); 

     // display title and result count 
     ?> 

     <h2><?php echo $feed->title; ?></h2> 
     <div> 
     <?php echo $feed->totalResults; ?> contact(s) found. 
     </div> 

     <?php 
     // parse feed and extract contact information 
     // into simpler objects 
     $results = array(); 
     foreach($feed as $entry){ 
     $xml = simplexml_load_string($entry->getXML()); 
     $obj = new stdClass; 
     $obj->name = (string) $entry->title; 
     $obj->orgName = (string) $xml->organization->orgName; 
     $obj->orgTitle = (string) $xml->organization->orgTitle; 

     foreach ($xml->email as $e) { 
      $obj->emailAddress[] = (string) $e['address']; 
     } 

     foreach ($xml->phoneNumber as $p) { 
      $obj->phoneNumber[] = (string) $p; 
     } 
     foreach ($xml->website as $w) { 
      $obj->website[] = (string) $w['href']; 
     } 

     $results[] = $obj; 
     } 
    } catch (Exception $e) { 
     die('ERROR:' . $e->getMessage()); 
    } 
    ?> 

    <?php 
    // display results 
    foreach ($results as $r) { 
    ?> 
    <div class="entry"> 
     <div class="name"><?php echo (!empty($r->name)) ? 
     $r->name : 'Name not available'; ?></div> 
     <div class="data"> 
     <table> 
      <tr> 
      <td>Organization</td> 
      <td><?php echo $r->orgName; ?></td> 
      </tr> 
      <tr> 
      <td>Email</td> 
      <td><?php echo @join(', ', $r->emailAddress); ?></td> 
      </tr> 
      <tr> 
      <td>Phone</td> 
      <td><?php echo @join(', ', $r->phoneNumber); ?></td> 
      </tr> 
      <tr> 
      <td>Web</td> 
      <td><?php echo @join(', ', $r->website); ?></td> 
      </tr> 
     </table> 
     </div> 
    </div> 
    <?php 
    } 
    ?> 

    </body> 
</html> 
+0

php.ini에서 최소한 E_ALL로 오류보고를 활성화하고 display_errors를 true로 변경하십시오. 그러면 스크립트가 실패하는 이유를 정확하게 알 수 있습니다. 그렇지 않으면이 정보는 PHP 오류 로그에서도 찾을 수 있습니다. –

답변

1

php.ini 포함 경로가 Zend 라이브러리를 가리 키도록 업데이트 했습니까?

C : \ ZendXXX \ library \ Zend에 라이브러리의 압축을 풀 었다고 가정 해 봅시다.

이 파일을 php.ini 파일에 추가하십시오. include_path = ".; C : \ ZendXXX \ library";