首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何上传图像在我的相册(错误401“认证所需”)?

如何上传图像在我的相册(错误401“认证所需”)?
EN

Stack Overflow用户
提问于 2016-03-29 16:06:57
回答 1查看 348关注 0票数 0

要在imgur.com it代码上上传相册中的图像:

代码语言:javascript
复制
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);

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

字符串(112)“{”数据“:{”错误“:”身份验证所需“、”请求“:”/3/image“、”方法“:”POST“}、”成功“:false、"status":401}”

因此,我们有一些问题:

  1. 我如何才能(在php上)?
  2. 在docs中,https://market.mashape.com/imgur/imgur-9需要粘贴Authorization HEADER AUTH。怎么抓到他?
EN

回答 1

Stack Overflow用户

发布于 2016-03-30 10:41:06

需要将它们连接到一个数组中,从而生成一个集合调用:

代码语言:javascript
复制
$headers = array('Authorization: Client-ID ' . $client_id, 'X-Mashape-Key: ' . $Mashape_Key)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36289509

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档