Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * oauth_guid.php
- *
- *
- *
- */
- /*
- * Get the http.php file from http://www.phpclasses.org/httpclient
- */
- require('http.php');
- require('oauth_client.php');
- $localhost = 'localhost';
- $dbuser = 'user';
- $dbpass = 'password';
- $dbname = 'dbname';
- $dbtable = 'dbtable';
- $client = new oauth_client_class;
- $client->debug = false;
- $client->debug_http = false;
- $client->server = 'Discogs';
- $f = $_GET["f"];
- $client->redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].
- dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/oauth_guid.php?f=' . $f;
- $client->client_id = 'client_id'; $application_line = __LINE__;
- $client->client_secret = 'client_secret';
- $f = $_GET["f"];
- /* if (!$f)
- {
- die('Could not get GUID : ' . mysql_error()); // remove ?
- } */
- if(($success = $client->Initialize()))
- {
- if(($success = $client->Process()))
- {
- $success = $client->CallAPI(
- 'http://api.discogs.com/oauth/identity',
- 'GET', array(), array('FailOnAccessError'=>true), $user);
- }
- $success = $client->Finalize($success);
- }
- if($client->exit)
- exit;
- if($success)
- {
- $link = mysql_connect($localhost, $dbuser, $dbpass);
- if (!$link)
- {
- die('Could not connect: ' . mysql_error()); // remove ?
- }
- $dbselect=mysql_select_db($dbname);
- if (!$dbselect)
- {
- die ("Can't use database $dbname! : " . mysql_error()); // remove ?
- }
- $accesstoken = $client->access_token;
- $accesstokensecret = $client->access_token_secret;
- $adddata = mysql_query("INSERT INTO $dbtable (accesstoken, accesstokensecret, guid) VALUES('$accesstoken' , '$accesstokensecret','$f' ) ") ;
- if (!$adddata)
- {
- die('Could not add accesstoken : ' . mysql_error()); // remove ?
- }
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>Discogs OAuth client results</title>
- </head>
- <body>
- <?php
- echo '<h1>', HtmlSpecialChars($user->username),
- ' you have logged in successfully with Discogs!</h1>' . "<br/>";
- echo "AccessToken=" . $client->access_token . "<br/>";
- echo "AccessTokenSecret=" . $client->access_token_secret . " <br/><br/>";
- echo "GUID=" . $f . " <br/><br/>";
- echo "You can now close this window. <br/><br/>";
- ?>
- </body>
- </html>
- <?php
- }
- else
- {
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>OAuth client error</title>
- </head>
- <body>
- <h1>OAuth client error</h1>
- <pre>Error: <?php echo HtmlSpecialChars($client->error); ?></pre>
- </body>
- </html>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement