Imgur API 3上传到帐户PHP

时间:2013-10-15 13:11:35

标签: php curl oauth imgur

我有以下匿名上传的代码就好了,但我似乎无法弄清楚我的生活如何登录我的帐户上传。我发现你需要使用OAuth并且需要每小时刷新你的令牌,但这是我似乎无法理解的东西,因为我不知道从哪里开始。

$handle = fopen($file_tmp, "r");
$data = fread($handle, $file_size);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
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_POSTFIELDS, array('image' => base64_encode($data)));
    $reply = curl_exec($ch);
curl_close($ch);
$reply = json_decode($reply);
$url = $reply->data->link;

来源:https://api.imgur.com/oauth2

0 个答案:

没有答案