2

我可以匿名上传以下代码,但我似乎一生都无法弄清楚如何登录我的帐户进行上传。我看到您需要使用 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

4

0 回答 0