Advertisement
crap_inhuman

oauth_guid.php

Jul 31st, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. <?php
  2. /*
  3.  * oauth_guid.php
  4.  *
  5.  *
  6.  *
  7.  */
  8.  
  9.     /*
  10.      *  Get the http.php file from http://www.phpclasses.org/httpclient
  11.      */
  12.     require('http.php');
  13.     require('oauth_client.php');
  14.  
  15.     $localhost = 'localhost';
  16.     $dbuser =  'user';
  17.     $dbpass = 'password';
  18.     $dbname = 'dbname';
  19.     $dbtable = 'dbtable';
  20.  
  21.     $client = new oauth_client_class;
  22.     $client->debug = false;
  23.     $client->debug_http = false;
  24.     $client->server = 'Discogs';
  25.     $f = $_GET["f"];
  26.     $client->redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].
  27.         dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/oauth_guid.php?f=' . $f;
  28.  
  29.     $client->client_id = 'client_id'; $application_line = __LINE__;
  30.     $client->client_secret = 'client_secret';
  31.  
  32.     $f = $_GET["f"];
  33.     /* if (!$f)
  34.     {
  35.         die('Could not get GUID : ' . mysql_error()); // remove ?
  36.     } */
  37.     if(($success = $client->Initialize()))
  38.     {
  39.         if(($success = $client->Process()))
  40.         {
  41.             $success = $client->CallAPI(
  42.             'http://api.discogs.com/oauth/identity',
  43.             'GET', array(), array('FailOnAccessError'=>true), $user);
  44.         }
  45.         $success = $client->Finalize($success);
  46.     }
  47.     if($client->exit)
  48.         exit;
  49.     if($success)
  50.     {
  51.         $link = mysql_connect($localhost, $dbuser, $dbpass);
  52.         if (!$link)
  53.         {
  54.             die('Could not connect: ' . mysql_error());  // remove ?
  55.         }
  56.         $dbselect=mysql_select_db($dbname);
  57.         if (!$dbselect)
  58.         {
  59.             die ("Can't use database $dbname! : " . mysql_error()); // remove ?
  60.         }
  61.         $accesstoken = $client->access_token;
  62.         $accesstokensecret = $client->access_token_secret;
  63.         $adddata = mysql_query("INSERT INTO $dbtable (accesstoken, accesstokensecret, guid) VALUES('$accesstoken' , '$accesstokensecret','$f' ) ") ;
  64.         if (!$adddata)
  65.         {
  66.             die('Could not add accesstoken : ' . mysql_error()); // remove ?
  67.         }
  68.  
  69. ?>
  70. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  71. <html>
  72. <head>
  73. <title>Discogs OAuth client results</title>
  74. </head>
  75. <body>
  76. <?php
  77.         echo '<h1>', HtmlSpecialChars($user->username),
  78.             ' you have logged in successfully with Discogs!</h1>' . "<br/>";
  79.         echo "AccessToken=" . $client->access_token . "<br/>";
  80.         echo "AccessTokenSecret=" . $client->access_token_secret . " <br/><br/>";
  81.         echo "GUID=" . $f . " <br/><br/>";
  82.         echo "You can now close this window. <br/><br/>";
  83.         ?>
  84. </body>
  85. </html>
  86. <?php
  87.     }
  88.     else
  89.     {
  90. ?>
  91. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  92. <html>
  93. <head>
  94. <title>OAuth client error</title>
  95. </head>
  96. <body>
  97. <h1>OAuth client error</h1>
  98. <pre>Error: <?php echo HtmlSpecialChars($client->error); ?></pre>
  99. </body>
  100. </html>
  101. <?php
  102.     }
  103.  
  104. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement