Drupal用のこのGmail連絡先インポートスクリプトの何が問題になっていますか?

StackOverflow https://stackoverflow.com/questions/827343

質問

Drupalにはgmail連絡先インポーターモジュールがあり、約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

次の致命的なエラーが表示されます:

  

致命的なエラー: path / to / site / sites / all / modules / dcl_importer / scripts / importGData.class内の非オブジェクトのメンバー関数 getAttribute()を呼び出します。 97行目のphp

スクリプトは次のとおりです。

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-&gt; 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:emailは、 Google Data API 。 Gmailの実装でもオプションです。使用しているモジュールは、それが存在すると想定し、存在しない場合は失敗します。

連絡先ごとの複数の電子メールアドレスは、注:コメントに従って処理されないままです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top