imgur如何在我的相册中上传图像(错误401“需要身份验证”)


imgur with How upload image in my album (error 401 "Authentication required")?

用于在imgur.com上传相册中的图像,其代码为:

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

但现在我们得到了错误的答案:

string(112)"{"data":{"error":"身份验证必需","请求":"/3/image","方法":"POST"},"成功":false,"状态":401}

结果我们有一些问题:

  1. 如何进行身份验证(在php上)
  2. 在文档CCD_ 2中需要粘贴CCD_。怎么找到他

需要将这些连接到一个数组中,从而进行一个集合调用:

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