0
Für in Alben auf imgur.com
es Code hochladen Bild:imgur mit php - Wie Bild in meinem Album hochladen (Fehler 401 "Authentifizierung erforderlich")?
if(isset($_FILES['upload']['tmp_name'])) {
$imgbinary = fread(fopen($_FILES['upload']['tmp_name'], "r"), filesize($_FILES['upload']['tmp_name']));
$image = 'data:image/png;base64,' . base64_encode($imgbinary);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://imgur-apiv3.p.mashape.com/3/image');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Mashape-Key: '. $xmash)); //. $xmash
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => $image));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('album' => $album_id));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('type' => 'base64'));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('name' => 'test_name'));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('title' => 'test title'));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('description' => 'blablabla'));
$reply = curl_exec($ch);
var_dump($reply);
curl_close($ch);
Aber jetzt sind wir Fehler in der Antwort erhalten:
string (112) "{" data ": {" Fehler ":" Authentifizierung erforderlich " "Anforderung": "/ 3/Bild", "Methode": "POST"}, "Erfolg": false, "status": 401}"
Im Ergebnis haben wir einige Fragen :
- Wie kann ich auth (auf PHP)?
- in Dok.
https://market.mashape.com/imgur/imgur-9
brauchen PasteAuthorization HEADER AUTH
. Wie kriegt man ihn?
Sie haben auch die Anwendungsschlüssel zu übergeben. Ich denke, das ist dein fehlender Schritt .. – cramopy
@cramopy Problem mit 'X-Mashape-Key' wurde gelöst, aber jetzt bekommen wir Fehler 'Authentifizierung erforderlich' ... – user6129461