Disqus验证返回空数据

时间:2014-01-22 20:56:42

标签: php

我正在尝试使用disqus身份验证创建一个登录系统,但即使我按照他们的说法完全按照他们的教程,用户也可以访问他们的系统,但是我没有得到任何数据...一切都返回null ...

    <?php

//This is a all-in-one example of API authentication and making API calls using OAuth
//More information on using OAuth with Disqus can be found here: http://disqus.com/api/docs/auth/

//error_reporting(E_ALL ^ E_NOTICE) ;

$PUBLIC_KEY = "mypk";
$SECRET_KEY = "mysk";
$redirect = "returning addr";

$endpoint = 'https://disqus.com/api/oauth/2.0/authorize?';
$endpoint = 'https://disqus.com/api/oauth/2.0/authorize/?';
$client_id = $PUBLIC_KEY;
$scope = 'read,write';
$response_type = 'code';

$auth_url = $endpoint.'&client_id='.$client_id.'&scope='.$scope.'&response_type='.$response_type.'&redirect_uri='.$redirect;

echo $auth_url;

// Trigger the initial authentication call to receive a code
echo "<h3>Trigger authentication -> <a href='".$auth_url."'>OAuth</a></h3>";


// Get the code to request access
$CODE = $_GET['code'];

if($CODE){

echo '<br>' . $CODE . '<br>';

// Build the URL and request the authentication token
extract($_POST);

$authorize = "authorization_code";

$url = 'https://disqus.com/api/oauth/2.0/access_token/?';
$fields = array(
  'grant_type'=>urlencode($authorize),
  'client_id'=>urlencode($PUBLIC_KEY),
  'client_secret'=>urlencode($SECRET_KEY),
  'redirect_uri'=>urlencode($redirect),
  'code'=>urlencode($CODE)
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, "&");

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

//execute post
$data = curl_exec($ch);

print_r($data);

//close connection
curl_close($ch);
}
?>

是的,我试图找到一些可以帮助我的东西......

0 个答案:

没有答案