Build a PHP 7 Laravel Book Search App Using Google Books API in Browser

You are currently viewing Build a PHP 7 Laravel Book Search App Using Google Books API in Browser

Build a PHP 7 Laravel Book Search App Using Google Books API in Browser

composer require scriptotek/google-books

<span class="pl-k">require_once</span>(<span class="pl-s">'vendor/autoload.php'</span>);
<span class="pl-k">use</span> <span class="pl-v">Scriptotek</span>\<span class="pl-v">GoogleBooks</span>\<span class="pl-v">GoogleBooks</span>;
 
<span class="pl-s1"><span class="pl-c1">
lt;/span>books</span> = <span class="pl-k">new</span> <span class="pl-v">GoogleBooks</span>([<span class="pl-s">'key'</span> => <span class="pl-s">'YOUR_API_KEY_HERE'</span>]);

<span class="pl-s1"><span class="pl-c1">
lt;/span>volume</span> = <span class="pl-s1"><span class="pl-c1">
lt;/span>books</span>-><span class="pl-c1">volumes</span>-><span class="pl-en">get</span>(<span class="pl-s">'kdwPAQAAMAAJ'</span>);

<span class="pl-s1"><span class="pl-c1">
lt;/span>volume</span> = <span class="pl-s1"><span class="pl-c1">
lt;/span>books</span>-><span class="pl-c1">volumes</span>-><span class="pl-en">byIsbn</span>(<span class="pl-s">'0521339057'</span>);

<span class="pl-k">foreach</span> (<span class="pl-s1"><span class="pl-c1">
lt;/span>books</span>-><span class="pl-c1">volumes</span>-><span class="pl-en">search</span>(<span class="pl-s">'Hello world'</span>) <span class="pl-k">as</span> <span class="pl-s1"><span class="pl-c1">
lt;/span>vol</span>) {
    <span class="pl-k">echo</span> <span class="pl-s1"><span class="pl-c1">
lt;/span>vol</span>-><span class="pl-c1">title</span> . <span class="pl-s">"\n"</span>;
}

<span class="pl-s1"><span class="pl-c1">
lt;/span>shelf</span> = <span class="pl-s1"><span class="pl-c1">
lt;/span>books</span>-><span class="pl-c1">bookshelves</span>-><span class="pl-en">get</span>(<span class="pl-s">'113555231101190020526'</span>, <span class="pl-s">'1002'</span>);

<span class="pl-k">foreach</span> (<span class="pl-s1"><span class="pl-c1">
lt;/span>books</span>-><span class="pl-c1">bookshelves</span>-><span class="pl-en">byUser</span>(<span class="pl-s">'113555231101190020526'</span>) <span class="pl-k">as</span> <span class="pl-s1"><span class="pl-c1">
lt;/span>shelf</span>) {
    <span class="pl-k">echo</span> <span class="pl-s">"<h2>$shelf->title</h2>\n"</span>;
    <span class="pl-k">echo</span> <span class="pl-s">"<ul>\n"</span>;
    <span class="pl-k">foreach</span> (<span class="pl-s1"><span class="pl-c1">
lt;/span>shelf</span>-><span class="pl-en">getVolumes</span>() <span class="pl-k">as</span> <span class="pl-s1"><span class="pl-c1">
lt;/span>vol</span>) {
        <span class="pl-k">echo</span> <span class="pl-s">"  <li>$vol->title</li>\n"</span>;
    }
    <span class="pl-k">echo</span> <span class="pl-s">"</ul>\n"</span>;
}

Scriptotek\GoogleBooks\GoogleBooksServiceProvider::class,
 

'GoogleBooks' => Scriptotek\GoogleBooks\GoogleBooksFacade::class,
 

$ php artisan vendor:publish --provider="Scriptotek\GoogleBooks\GoogleBooksServiceProvider"
 

{
<span class="pl-s"><span class="pl-pds">"</span>error<span class="pl-pds">"</span></span>: {
  <span class="pl-s"><span class="pl-pds">"</span>errors<span class="pl-pds">"</span></span>: [
   {
    <span class="pl-s"><span class="pl-pds">"</span>domain<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>global<span class="pl-pds">"</span></span>,
    <span class="pl-s"><span class="pl-pds">"</span>reason<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>unknownLocation<span class="pl-pds">"</span></span>,
    <span class="pl-s"><span class="pl-pds">"</span>message<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Cannot determine user location for geographically restricted operation.<span class="pl-pds">"</span></span>
   }
  ],
  <span class="pl-s"><span class="pl-pds">"</span>code<span class="pl-pds">"</span></span>: <span class="pl-c1">403</span>,
  <span class="pl-s"><span class="pl-pds">"</span>message<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Cannot determine user location for geographically restricted operation.<span class="pl-pds">"</span></span>
}
}

<span class="pl-s1"><span class="pl-c1">
lt;/span>books</span> = <span class="pl-k">new</span> <span class="pl-v">GoogleBooks</span>([<span class="pl-s">'country'</span> => <span class="pl-s">'NO'</span>]);

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply