2016-03-29 19 views
0

:imgur - Albümümde nasıl upload image (error 401 "Authentication required")? <code>imgur.com</code> o kodu albümlerde resim yükleyerek için

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

Fakat şimdi yanıtında hata alıyorum şunlardır:

dize (112) "{" veri ": {" hata ":" Doğrulama " "istek gerekli": "/ 3/resim", "yöntem": "POST"}, "başarı": false, "durum": 401}" Sonuç olarak

bazı sorularım var :

  1. Nasıl yapabilirim (php'de)?
  2. belgelerinde https://market.mashape.com/imgur/imgur-9 yapıştırması gerekiyor Authorization HEADER AUTH. Onu nasıl alsın? bir diziye bu katılmak için
+0

ayrıca uygulama anahtarı geçmek zorunda. Bence bu senin eksik adımın .. – cramopy

+0

@ X-Mashape-Key ile cramopy problemi çözüldü, ama şimdi "Kimlik Doğrulama gerekli" hatası alıyoruz ... – user6129461

cevap

0

ihtiyaç ve dolayısıyla bir set çağrı:

$headers = array('Authorization: Client-ID ' . $client_id, 'X-Mashape-Key: ' . $Mashape_Key) 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);