view goodreads/callback.php @ 60:05f29eb72283 default tip

review from DB not working???
author Charlie Root
date Sun, 09 Jun 2019 06:50:44 -0400
parents a67bf725e87b
children
line wrap: on
line source

<?php

require_once('GoodreadsAPI.php');

session_start();
if($_SESSION['oauth_token'] !== $_REQUEST['oauth_token'])
{
  //token expired get a new one. You can clear session over here and redirect user to the login link
  die('Goodreads connection expired- please reconnect');
}


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

$access_token = $obj->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['access_token'] = $access_token;

//print_r($access_token);

unset ($_SESSION['oauth_token'], $_SESSION['oauth_token_secret'] ,$obj);

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

$content = $obj->doGet('http://www.goodreads.com/api/auth_user');
//print_r($content);

$xml = new SimpleXMLElement($content);
$grID = $xml->user->attributes()->id;
//echo $grID;

$userID = $_SESSION['UserID'];
$backLoc = "http://www.yournextread.com/" . urldecode($_SESSION['backLocation']);

include "db.php";
$add = "CALL addGoodreadsID($userID,$grID)"; 
//echo $add;
$run = mysqli_query($link, $add); //add the book to the list in usersave


unset ($obj);

	echo "<html>
		<link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\">
		<head>
		<title>Goodreads Connection Successful</title>
		</head>
		<body>

		<h1>YourNextRead</h1>
		<p>Thank you! You have successfully connected YourNextRead and Goodreads!</p>
		<div style=\"border-bottom:solid;border-bottom-width:2px;border-bottom-color:#ffffff;height:1px;width:100%;margin-top:10px;margin-bottom:10px;\"></div>	
		<p>Use this button to import your Goodreads shelves into YourNextRead:</p>
		<center><A HREF=\"http://www.yournextread.com/goodreads/getGoodreadsShelves.php?userID=$userID&grID=$grID\"><img src=\"http://www.yournextread.com/images/goodreads-import.png\" style=\"border:0px;display:block;\" alt=\"Import from Goodreads\"></a></center>
		<p>Use this button to export all of your YourNextRead saved lists into Goodreads:</p> 
		<center><A HREF=\"http://www.yournextread.com/goodreads/syncGoodreadsShelves.php?userID=$userID&grID=$grID\"><img src=\"http://www.yournextread.com/images/goodreads-export.png\" style=\"border:0px;display:block;\" alt=\"Export to Goodreads\"></a></center>
		<p><b>Note</b> - if you have many saved lists the export process can take some time. You may prefer to export individual lists, using the <img src=\"http://www.yournextread.com/images/goodreads-save.png\" style=\"border:0px;display:inline;\" alt=\"Save to Goodreads\"> button in the 'Saved List' tab</p>
		<div style=\"border-bottom:solid;border-bottom-width:2px;border-bottom-color:#ffffff;height:1px;width:100%;margin-top:10px;margin-bottom:10px;\"></div>
		<p>Click <a href=\"$backLoc\">here</a> to go to your previous page on YourNextRead</p>
		<p><a href=\"$backLoc\">www.YourNextRead.com</a></p>

		</body>
		</html>";

//Header( "Location: ../xml/getGoodReadsShelves.php?userID=$userID&grID=$grID" ); 
?>