2017-06-03 167 views
1

因此,我的網站向我的網站上的PHP頁面發出AJAX請求。它首先登錄並獲取用戶Pastebin會話ID,然後使用它來查看該用戶所做的所有粘貼。唯一的問題是我不斷收到錯誤:錯誤的API請求,無效或過期的api_user_key。我覺得我做了會話ID部分正確的(我甚至嘗試生成一個與「錯誤的API請求,無效或過期的api_user_key」

Javascript代碼:

var logindata = {}; 
var sessionid; 

$("#login").click(function() { 
    $.each($('#loginform').serializeArray(), function(i, field) { 
     logindata[field.name] = field.value; 
    }); 

    $.get("pb_login.php?username=" + logindata['pastebinusername'] + "&password=" + logindata['pastebinpassword'], function(data, status) { 
     alert(data); 
     sessionid = data; 

     $.get("pb_getlists.php?sessionid=" + sessionid, function(data, status) { 
      alert(sessionid); 
      alert(data); 
     }); 
    }); 
}); 

pb_login.php

<?php 
$api_dev_key = 'API key here'; 
$api_user_name = urlencode($_GET['username']); 
$api_user_password = urlencode($_GET['password']); 
$url = 'https://pastebin.com/api/api_login.php'; 

$ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_dev_key='.$api_dev_key.'&api_user_name='.$api_user_name.'&api_user_password='.$api_user_password.''); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_NOBODY, 0); 

$response = curl_exec($ch); 
echo $response; 
?> 

pb_getlists.php

<?php 
$api_dev_key = 'API key here'; 
$api_user_key = $_GET['sessionid']; 
//$api_user_key = '43ded5a66e8ed08603804fe2487c8ab7'; 
$api_results_limit = '250'; 
$url = 'https://pastebin.com/api/api_post.php'; 
$ch = curl_init($url); 

curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=list&api_user_key='.$api_user_key.'&api_dev_key='.$api_dev_key.'&api_results_limit='.$api_results_limit.''); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_NOBODY, 0); 

$response = curl_exec($ch); 
echo $response; 
?> 

在此先感謝。:)

編輯:我真的開始認爲這是一個Pastebin API的問題。我不會感到驚訝,如果它是我搞砸的東西,但我不知道它會是什麼。

回答

1

耶。我是個白癡。

我將錯誤的IP列入白名單(您需要將IP列入白名單才能使用Pastebin API)。我正在使用LAMP虛擬機進行測試,並且在我開始在我的實際網站上做東西時忘記更改它。

相關問題