2017-06-03 7 views
1

Also meine Website macht eine AJAX-Anfrage an eine PHP-Seite auf meiner Website. Es meldet sich zuerst an und ruft die Pastebin-Sitzungs-ID des Benutzers ab, um alle Pasten anzuzeigen, die von diesem Benutzer erstellt wurden. Das einzige Problem ist, dass ich immer einen Fehler bekomme: Ungültige API-Anfrage, ungültiger oder abgelaufener api_user_key. Ich glaube, ich habe die Session-ID-Teil richtig (ich habe sogar versucht, ein mit"Schlechte API-Anfrage, ungültige oder abgelaufene api_user_key"

Javascript-Code zu erzeugen:

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; 
?> 

Vielen Dank im Voraus :)

EDIT: Ich fange wirklich an zu denken, dass es ein Problem mit Pastebins API ist. Ich wäre nicht überrascht, wenn es etwas Dummes wäre, was ich vermasselt hätte, aber ich habe keine Ahnung, was es sein könnte.

Antwort

1

Yay. Ich bin ein Idiot.

Ich habe die falsche IP-Adresse auf die weiße Liste gesetzt (Sie müssen eine IP-Adresse auf die weiße Liste setzen, um die Pastebin-API zu verwenden). Ich habe mit einer LAMP-VM getestet und vergessen, sie zu ändern, als ich anfing, Sachen auf meiner tatsächlichen Website zu tun.

Verwandte Themen