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.