Help using Zend Gdata with Google Books

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Help using Zend Gdata with Google Books

reynierpm
Hi every:
I have this code to get some books info from Google Books API:

public function GoogleBooks() {
        $path = '../libraries/';
        set_include_path(get_include_path() . PATH_SEPARATOR . $path);

        require_once 'zend/Loader.php';
        Zend_Loader::loadClass('Zend_Gdata_Books');
        Zend_Loader::loadClass('Zend_Gdata_Books_VolumeQuery');

        $isbn = $this->request->get['isbn'];

        try {
            $books = new Zend_Gdata_Books();
            $query = new Zend_Gdata_Books_VolumeQuery;
            $query->setQuery(urlencode($isbn));
            $feed = $books->getVolumeFeed($query);
        } catch (Exception $e) {
            die('ERROR:' . $e->getMessage());
        }

        foreach ($feed as $entry) {
            $title = $entry->getTitle()->text; // get Title
            $author = implode(", ", $entry->getCreators()); // get Authors
            $publisher = implode(", ", $entry->getPublishers()); // get Publishers
            $description = implode(", ", $entry->getDescriptions()); // get Description
            $identifiers = implode(", ", $entry->getIdentifiers()); // get Identifiers
            $categories = implode(", ", $entry->getSubjects()); // get Categories
            $year_pub = implode(',', $entry->getDates()); // get Year Publisher
            $volume_id = $entry->getVolumeId(); // get Volume ID
            $link_to_book = $entry->getInfoLink()->getHref();

            // get Image
            $image = $entry->getThumbnailLink()->getHref();

            // get ISBN
            $x = $entry->getIdentifiers();
            $isbn10 = str_replace("ISBN:", "", @$x[1]->text);
            $isbn13 = str_replace("ISBN:", "", @$x[2]->text);

            // get Format
            $x = $entry->getFormats();

            $pages = @$x[0];
            $pages = $pages->text;
            $pages = explode(" ", $pages);

            $book_info = array(
                'title' => ($title) ? $title : 'Sin título',
                'link' => ($link_to_book) ? $link_to_book : '',
                'author' => ($author) ? $author : 'Desconocido',
                'publisher' => ($publisher) ? $publisher : 'Desconocida',
                'categories' => ($categories) ? $categories : 'No disponible',
                'pubdate' => $year_pub,
                'thumb_url' => ($image) ? $image : '',
                'isbn10' => ($isbn10) ? $isbn10 : '',
                'isbn13' => ($isbn13) ? $isbn13 : '',
                'pages' => ($pages) ? $pages[0] : '',
                'desc' => isset($description) ? $description : 'Desconocido'
            );
        }

        $this->load->library('json');
        echo $this->response->setOutput(Json::encode($book_info));
    }

But now with 1.11.7 I'm getting this error:
Warning: DOMDocument::loadXML() [domdocument.loadxml]: StartTag: invalid element name in Entity, line: 1 in D:\Webserver\htdocs\libcommerce\libraries\zend\Gdata\App.php on line 820Warning: DOMDocument::loadXML() [domdocument.loadxml]: Extra content at the end of the document in Entity, line: 1 in D:\Webserver\htdocs\libcommerce\libraries\zend\Gdata\App.php on line 820Notice: Undefined variable: php_errormsg in D:\Webserver\htdocs\libcommerce\libraries\zend\Gdata\App.php on line 826ERROR:DOMDocument cannot parse XML:

And I don't know where it fails. Any help?
Reply | Threaded
Open this post in threaded view
|

Re: Help using Zend Gdata with Google Books

Trevor Johns-2
It sounds like you're getting back an invalid response from the server.

Try grabbing a network trace using tcpdump/wireshark and see what's coming
back from the server:

http://code.google.com/apis/gdata/articles/wireshark.html

--
Trevor Johns
Developer Programs Engineer, Android
http://developer.android.com





On Wed, Jun 15, 2011 at 7:47 AM, reynierpm <[hidden email]> wrote:

> Hi every:
> I have this code to get some books info from Google Books API:
>
> public function GoogleBooks() {
>        $path = '../libraries/';
>        set_include_path(get_include_path() . PATH_SEPARATOR . $path);
>
>        require_once 'zend/Loader.php';
>        Zend_Loader::loadClass('Zend_Gdata_Books');
>        Zend_Loader::loadClass('Zend_Gdata_Books_VolumeQuery');
>
>        $isbn = $this->request->get['isbn'];
>
>        try {
>            $books = new Zend_Gdata_Books();
>            $query = new Zend_Gdata_Books_VolumeQuery;
>            $query->setQuery(urlencode($isbn));
>            $feed = $books->getVolumeFeed($query);
>        } catch (Exception $e) {
>            die('ERROR:' . $e->getMessage());
>        }
>
>        foreach ($feed as $entry) {
>            $title = $entry->getTitle()->text; // get Title
>            $author = implode(", ", $entry->getCreators()); // get Authors
>            $publisher = implode(", ", $entry->getPublishers()); // get
> Publishers
>            $description = implode(", ", $entry->getDescriptions()); // get
> Description
>            $identifiers = implode(", ", $entry->getIdentifiers()); // get
> Identifiers
>            $categories = implode(", ", $entry->getSubjects()); // get
> Categories
>            $year_pub = implode(',', $entry->getDates()); // get Year
> Publisher
>            $volume_id = $entry->getVolumeId(); // get Volume ID
>            $link_to_book = $entry->getInfoLink()->getHref();
>
>            // get Image
>            $image = $entry->getThumbnailLink()->getHref();
>
>            // get ISBN
>            $x = $entry->getIdentifiers();
>            $isbn10 = str_replace("ISBN:", "", @$x[1]->text);
>            $isbn13 = str_replace("ISBN:", "", @$x[2]->text);
>
>            // get Format
>            $x = $entry->getFormats();
>
>            $pages = @$x[0];
>            $pages = $pages->text;
>            $pages = explode(" ", $pages);
>
>            $book_info = array(
>                'title' => ($title) ? $title : 'Sin título',
>                'link' => ($link_to_book) ? $link_to_book : '',
>                'author' => ($author) ? $author : 'Desconocido',
>                'publisher' => ($publisher) ? $publisher : 'Desconocida',
>                'categories' => ($categories) ? $categories : 'No
> disponible',
>                'pubdate' => $year_pub,
>                'thumb_url' => ($image) ? $image : '',
>                'isbn10' => ($isbn10) ? $isbn10 : '',
>                'isbn13' => ($isbn13) ? $isbn13 : '',
>                'pages' => ($pages) ? $pages[0] : '',
>                'desc' => isset($description) ? $description : 'Desconocido'
>            );
>        }
>
>        $this->load->library('json');
>        echo $this->response->setOutput(Json::encode($book_info));
>    }
>
> But now with 1.11.7 I'm getting this error:
> Warning: DOMDocument::loadXML() [domdocument.loadxml]: StartTag: invalid
> element name in Entity, line: 1 in
> D:\Webserver\htdocs\libcommerce\libraries\zend\Gdata\App.php on line
> 820Warning: DOMDocument::loadXML() [domdocument.loadxml]: Extra content at
> the end of the document in Entity, line: 1 in
> D:\Webserver\htdocs\libcommerce\libraries\zend\Gdata\App.php on line
> 820Notice: Undefined variable: php_errormsg in
> D:\Webserver\htdocs\libcommerce\libraries\zend\Gdata\App.php on line
> 826ERROR:DOMDocument cannot parse XML:
>
> And I don't know where it fails. Any help?
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/Help-using-Zend-Gdata-with-Google-Books-tp3599585p3599585.html
> Sent from the Zend gdata mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>