문제

Drupal에는 Gmail Contact 수입 업체 모듈이 있으며 현재 약 7 개월 동안 작동하는 데 있어서는 너무 클릭되었습니다. 나는 문제를 디버깅 할 수있는 절단이없고, 관리자는 사라졌으며, 이것이 일을하는 데 중요한 부분이라고 생각합니다. 그래서 나는 도움을 위해 stackoverflow로 돌아갑니다.

문제 : 자격 증명을 채우고 스크립트에 연락처를 다시 가져 오라고 말하면 기본적으로 25를 가져옵니다. 제대로 작동합니다.

쿼리 중 URL을 변경하여 더 많은 연락처를 찾으라고 말하면 다음과 같습니다.

http://www.google.com/m8/feeds/contacts/default/thin  

이에:

http://www.google.com/m8/feeds/contacts/default/thin?max-results=1000

다음과 같은 치명적인 오류가 발생합니다.

치명적인 오류 : 회원 기능을 호출합니다 getAttribute() 객체가 아닌 사람에 path/to/site/sites/all/modules/dcl_importer/scripts/importGData.class.php 97 행

다음은 스크립트입니다.

class GDataMailer {
    static $url_ClientLogin = 'https://www.google.com/accounts/ClientLogin';
    static $url_Feed = 'http://www.google.com/m8/feeds/contacts/default/thin?max-results=65535';

    function newCurlSession($URL, $auth = null) {
        $curl = curl_init();

        $opts = array(
            CURLOPT_URL => $URL,
            CURLOPT_REFERER => '',
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
        );
        if (null != $auth) {
            $opts[CURLOPT_HTTPHEADER] = array(
               'Authorization: GoogleLogin auth='.$auth,
            );
        }
        curl_setopt_array($curl, $opts);
        return $curl;
    }

    function useCurlForPost($curl, $params) {
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
        return $curl;
    }

    function getAuthToken($login, $password) {
        $curl = $this->useCurlForPost($this->newCurlSession(self::$url_ClientLogin), array(
           'accountType' => 'HOSTED_OR_GOOGLE',
           'Email' => $login,
           'Passwd' => $password,
           'service' => 'cp',
           'source' => 'Drupal-Contact-Importer',
        ));
        $resp = curl_exec($curl);

        // Look for the important stuff:
        preg_match_all('/Auth=([^\s]*)/si', $resp, $matches);
        if (isset($matches[1][0])) {
            return $matches[1][0];
        } else {
           return false;
        }
    }

    function getAddressbook($login, $password) {
        // check if username and password was given:
        if ((isset($login) && trim($login)=="") || (isset($password) && trim($password)==""))
        {
            $args = func_get_args();
            drupal_set_message('Incorrect login information given: '.print_r($args, true), 'error');
            return false;
        }

        // Get the GData auth token:
        $auth = $this->getAuthToken($login, $password);
        if (false === $auth) {
            drupal_set_message('Login failed', 'error');
            return false;
        }        

        $curl = $this->newCurlSession(self::$url_Feed, $auth);
        $data = curl_exec($curl);

        $doc = new DOMDocument();
        $doc->loadXML($data);
        $path = new DOMXPath($doc);
        $path->registerNamespace('a', 'http://www.w3.org/2005/Atom');
        $path->registerNamespace('gd', 'http://schemas.google.com/g/2005');
        $nodes = $path->query('//a:entry');
        $num = $nodes->length;

        $contacts = array();
        for ($x = 0; $x < $num; $x++) {
            $entry = $nodes->item($x);
            $tnodes = $path->query('a:title', $entry);
            $nnode = $tnodes->item(0);
            $name = $nnode->textContent;
            $enodes = $path->query('gd:email', $entry);
            $mnode = $enodes->item(0);
            $email = $mnode->getAttribute('address');
            // NOTE: Keep in mind that $mnode->getAttribute('rel') tells you what kind of email it is.
            // NOTE: Also remember that there can be multiple emails per entry!
            if (empty($name)) {
                $contacts[] = $email;
            } else {
                $contacts[$name] = $email;
            }
        }        

        return $contacts;
    }
}

97 행입니다 $email = $mnode->getAttribute('address'); 끝 근처에 라인.

더 이상 그 오류를 얻지 못하고 Drupal 커뮤니티 에서이 일을하게되도록 여기서 무엇을 변경할 수 있습니까? 나는 25 개가 아니라 모든 사람의 연락처 목록을 가져오고 싶다.

도움이 되었습니까?

해결책

직접 테스트하지 않고도 96-104 행을 다음과 같이 교체하려고합니다.

$mnode = $enodes->item(0);
if (isset($mnode) && is_object($mnode)) {
    $email = $mnode->getAttribute('address');
    // NOTE: Keep in mind that $mnode->getAttribute('rel') tells you what kind of email it is.
    // NOTE: Also remember that there can be multiple emails per entry!
    if (!empty($email)) {
        if (empty($name)) {
            $contacts[] = $email;
        } else {
            $contacts[$name] = $email;
        }
    }
}

GD : 이메일은 선택 요소입니다. Google Data API. Gmail의 구현에서도 선택 사항입니다. 사용중인 모듈은 존재하지 않을 때 존재하고 실패한다고 가정합니다.

연락처 당 여러 전자 메일 주소는 주석에 따라도 모으지 않고 남아 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top