Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

goodreads.com php

Posted on 2012-03-29
5
Medium Priority
?
966 Views
Last Modified: 2012-03-30
Hey guys,

I was wondering if anyone knew any sites or tutorials that would assist me in getting back book reviews from http://www.goodreads.com api.  There are no php samples to give me a head start.  Has anyone used the api from goodreads?

thanks in advance
0
Comment
Question by:MK15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
Derokorian earned 2000 total points
ID: 37782728
I would look at the cURL library for PHP -> http://www.php.net/manual/en/book.curl.php
Then the URL you send a request to with cURL would be built using the different API Methods listed here http://www.goodreads.com/api See my example below:

<?php

$GoodReads_API_KEY = 'Your_Key'; // Replace with your key

$bookurl = 'http://www.goodreads.com/api/book_url/Ender%27s%2BGame?key='.$GoodReads_API_KEY; // specific url to request a book, this can be build dynamically by inserting different methods where it says book_url and such. See the API docs to see more about how the different URLs should be look

$ch = curl_init(); // Initialize curl  handle
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 5 second timeout
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the result on success, rather than just TRUE
curl_setopt($ch, CURLOPT_URL, $bookurl); // Set the url for curl to request to

$response = curl_exec($ch); // makes the request and gets the response

// Process $response as xml 
$xml = new SimpleXML($response);

Open in new window

0
 

Author Comment

by:MK15
ID: 37784853
hi,
let me start of by thanking you for your help.

I have managed to retrieve the data without creating an xml object, however there is a lot of data which i wish to remove. i want only the iframe enclosing the review and nothing else, how would you suggest i tackle this issue.


$bookurl = 'http://www.goodreads.com/book/isbn?isbn=0441172717&key='.$GoodReads_API_KEY;
// specific url to request a book, this can be build dynamically by inserting different methods where it says book_url and such. See the API docs to see more about how the different URLs should be look

$ch = curl_init(); // Initialize curl  handle
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 5 second timeout
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the result on success, rather than just TRUE
curl_setopt($ch, CURLOPT_URL, $bookurl); // Set the url for curl to request to

$response = curl_exec($ch); // makes the request and gets the response

// Process $response as xml 
$xml = new SimpleXMLElement($response);
echo '<pre>';
print_r($response);
echo '</pre>'

Open in new window


result

  
    true
      
    
  
  
  53732
  
  
  
  
  http://www.goodreads.com/images/nocover-111x148.jpg
  http://www.goodreads.com/images/nocover-60x80.jpg
  1990
  9
  1
  Ace/Berkley Books
  eng
  false
  
  
  234225
  137
  3634639
  book
  
  
  
  1965
  Dune
  5:79751|4:52480|3:32518|2:11728|1:9303|total:185780
  186613
  742519
  252551
  4399


  
  
  
  
  
  
  
  
  
  
    


    
    58
        
    
    
    
    3.88
    293472
    7134
  
  
    
    
      
  #goodreads-widget {
    font-family: georgia, serif;
    padding: 18px 0;
    width:565px;
  }
  #goodreads-widget h1 {
    font-weight:normal;
    font-size: 16px;
    border-bottom: 1px solid #BBB596;
    margin-bottom: 0;
  }
  #goodreads-widget a {
    text-decoration: none;
    color:#660;
  }
  iframe{
    background-color: #fff;
  }
  #goodreads-widget a:hover { text-decoration: underline; }
  #goodreads-widget a:active {
    color:#660;
  }
  #gr_footer {
    width: 100%;
    border-top: 1px solid #BBB596;
    text-align: right;
  }
  #goodreads-widget .gr_branding{
    color: #382110;
    font-size: 11px;
    text-decoration: none;
    font-family: verdana, arial, helvetica, sans-serif;
  }


  
Dune Reviews

//---------------------------------------------------------------------------------------------------------------------there is an iframe here which encloses the reviews - i need to have this iframe and nothing else.
  
  

    Reviews from Goodreads.com
  



      ]]>
    
  
  
          
          
          
          
          
          
          
          
          
          
      
  
    
  8
  
  http://www.goodreads.com/book_link/follow/8?book_id=53732

  1027
  
  http://www.goodreads.com/book_link/follow/1027?book_id=53732

  9
  
  http://www.goodreads.com/book_link/follow/9?book_id=53732

  4
  
  http://www.goodreads.com/book_link/follow/4?book_id=53732

  2
  
  http://www.goodreads.com/book_link/follow/2?book_id=53732

  10
  
  http://www.goodreads.com/book_link/follow/10?book_id=53732

  5
  
  http://www.goodreads.com/book_link/follow/5?book_id=53732

  2102
  
  http://www.goodreads.com/book_link/follow/2102?book_id=53732

  1602
  
  http://www.goodreads.com/book_link/follow/1602?book_id=53732

  107
  
  http://www.goodreads.com/book_link/follow/107?book_id=53732

  7
  
  http://www.goodreads.com/book_link/follow/7?book_id=53732

  1
  
  http://www.goodreads.com/book_link/follow/1?book_id=53732

  
  
    
166801
1

45935


two-volume omnibus series.
    
    See also:
    * Prelude to Dune
    * Legends of Dune
]]>




17
8
true

Open in new window


many thanks for your help, it is very much appreciated.
0
 
LVL 9

Expert Comment

by:rinfo
ID: 37786527
Isnt this the same question framed in a different way.
I have provided a solution in that question .
Please try that.
0
 
LVL 10

Expert Comment

by:Derokorian
ID: 37787180
$bookurl = 'http://www.goodreads.com/book/isbn?isbn=0441172717&key='.$GoodReads_API_KEY;

Open in new window

Notice the URL you used doesn't make a request for the API but rather goes to the site.
0
 

Author Closing Comment

by:MK15
ID: 37789686
thanks for your help mate
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question