Solved

goodreads.com php

Posted on 2012-03-29
5
896 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
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
Derokorian earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php ssh2_scp_send 1 46
Paypal 502 Error 3 62
How can I upload multiple images from a HTML form? 2 17
How do I put a session for a radio button? 4 12
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

948 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now