view goodreads/addToShelf.php @ 50:99a730ffeaf6

more parameterisation
author Charlie Root
date Sun, 27 Jan 2019 14:24:02 -0500
parents 077b0a0a3e6d
children
line wrap: on
line source

<?php

require_once('GoodreadsAPI.php');

session_start();

$isbn=$_GET['isbn'];
$shelf=$_GET['shelf'];

$url= "http://www.goodreads.com/book/isbn?isbn=" . $isbn . "&key=8vxmKmAn8AVolobtvBbMIg";

$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_ENCODING , "gzip");
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);

$ret = preg_replace("/[^[:alnum:][:punct:][:space:]]/","",$ret);
$xml = new SimpleXMLElement($ret);
		
$book_id = $xml->book->id;	
echo $book_id;

$access_token = $_SESSION['access_token'];
print_r($access_token);

$obj = new GoodreadsApi(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

$content = $obj->doPost('http://www.goodreads.com/shelf/add_to_shelf.xml', array("name" => "$shelf", "book_id" => "$book_id"));
print_r($content);

unset ($obj);

?>