Google API联系人导入失败,出现xml错误

时间:2015-07-15 00:37:13

标签: php xml google-api

$gClient = new \Google_Client();
$gClient->setApplicationName('Login and Contacts');
$gClient->setClientId(GOOGLE_CLIENT_ID);
$gClient->setClientSecret(GOOGLE_CLIENT_SECRET);
$gClient->setRedirectUri(GOOGLE_REDIRECT_URL);
$gClient->setDeveloperKey(GOOGLE_DEVELOPER_KEY);
$gClient->setScopes("https://www.google.com/m8/feeds/");

在上面创建Google客户端

    $google_oauthV2 = new \Google_Oauth2Service($gClient);

            if (isset($_GET['code'])){
            $gClient->authenticate($_GET['code']);
            $_SESSION['token'] = $gClient->getAccessToken();

            $req = new \Google_HttpRequest("https://www.google.com/m8/feeds/contacts/default/full");
            $val = $gClient->getIo()->authenticatedRequest($req);

            **$xml = simplexml_load_string($val->getResponseBody());**

            $xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$output_array = array();
            foreach ($xml->entry as $entry) {
                foreach ($entry->xpath('gd:email') as $email) {
                    $title = (string)$entry->title;
                    //if(trim($title) == '') continue;
                    $output_array[] = array((string)$entry->title, (string)$email->attributes()->address);
                }
            }
            echo "<PRE>";
            print_r($output_array);

高于 $ xml = simplexml_load_string($ val-&gt; getResponseBody()); 抛出错误就像 simplexml_load_string()第7行:解析器错误:打开和结束标记不匹配:第216行的app / controllers / profile.php中的元行1和头

任何指针都会有所帮助。

0 个答案:

没有答案