1
试图使匿名上传imgur图片的脚本生效。我运行它时只是空白页面。我需要发布带有标题和说明的图像(以64位字符串格式)。对不起,我的英文和代码。使用php在imgur上上传图片
<?
header ("Content-type: image/png");
$im = ImageCreate (200, 100);
$couleur_fond = ImageColorAllocate ($im, 255, 0, 0);
$client_id="d9514d92012b55a";
$pvars = base64_encode($im);
$timeout = 30;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id . ', title: title, description: description'));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
$out = curl_exec($curl);
curl_close ($curl);
$pms = json_decode($out,true);
$url=$pms['data']['link'];
?>
相关:http://stackoverflow.com/questions/4372710/php-curl-https – AllInOne
它看起来像你的代码来自[本博客文章](http://subinsb.com/uploading-images-using- imgur-API中的PHP)。你的代码似乎缺少一些东西,而你的'client_id'是无效的。我只是使用该博客文章中的代码和有效的'client_id'来设置它,它工作正常。 – APAD1