Video uploaded via API(v3) not attach to my account in Imgur

Viewed 152

Code Snippet:

Here is my code snippet:

function uploadByCurl($uploadFilePath, $accessToken){
    $ch = curl_init();
    $mimeType = mime_content_type($uploadFilePath);
    $fileType = '';
    if(strpos($mimeType, 'image')!==false){
        $fileType = 'image';
    }else if(strpos($mimeType, 'video')!==false){
        $fileType = 'video';
    }
    if(!$fileType){
        return false;
    }
    $filename = basename($uploadFilePath);
    $options = [
        CURLOPT_URL => 'https://api.imgur.com/3/upload',
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Authorization:Bearer ' . $accessToken,
        ],
        CURLOPT_POSTFIELDS => [
            //$fileType's value can be 'image' or 'video'
            $fileType => new \CURLFile($uploadFilePath),
            'type' => 'file',
            'name' => $filename,
            'title' => $filename,
            'description' => $filename,
        ],
        //In case you're in Windows, sometimes will throw error if not set SSL verification to false
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_TIMEOUT => 30,
    ];
    //In case you need a proxy
    //$options[CURLOPT_PROXY] = 'http://127.0.0.1:1087';
    // var_dump($options);exit;
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    if(curl_errno($ch)){
        echo 'Error: ' . curl_error($ch);
    }
    return $result;
}

$uploadFilePath = '/path/to/YOU_VIDEO.mp4';
$accessToken = '<YOU ACCESS TOKEN>';
$result = uploadByCurl($uploadFilePath, $accessToken);
var_dump($result);

Uploading image

The code snippet above can be use to upload image and video, for image, it works fine, successfully upload image and return the image link, and the most important is, the image have attached to my Imgur account, the response json is like this:

{
  "data": {
    "id": "C1CuRYw",
    "title": "Xnip2020-04-04_15-43-41.jpg",
    "description": "Xnip2020-04-04_15-43-41.jpg",
    "datetime": 1585987477,
    "type": "image/jpeg",
    "animated": false,
    "width": 748,
    "height": 632,
    "size": 126123,
    "views": 0,
    "bandwidth": 0,
    "favorite": false,
    "account_id": 96115121,
    "is_ad": false,
    "in_most_viral": false,
    "has_sound": false,
    "tags": [],
    "ad_type": 0,
    "ad_url": "",
    "edited": "0",
    "in_gallery": false,
    "deletehash": "uTg1rOZhEggKjgR",
    "name": "Xnip2020-04-04_15-43-41.jpg",
    "link": "https://i.imgur.com/C1CuRYw.jpg"
  },
  "success": true,
  "status": 200
}

Uploading video

I can successfully upload video too, and response json format is the same as uploading image:

{
  "status": 200,
  "success": true,
  "data": {
    "id": "SHCsEXK",
    "deletehash": "44oeDQCmP0Oba3o",
    "title": "testvideo.mp4",
    "description": "testvideo.mp4",
    "name": "",
    "type": "video/mp4",
    "width": 0,
    "height": 0,
    "size": 0,
    "views": 0,
    "bandwidth": 0,
    "animated": true,
    "favorite": false,
    "in_gallery": false,
    "in_most_viral": false,
    "has_sound": false,
    "is_ad": false,
    "link": "https://i.imgur.com/SHCsEXK.mp4",
    "tags": [],
    "processing": {
      "status": "pending"
    },
    "datetime": 1585986090,
    "mp4": "https://i.imgur.com/SHCsEXK.mp4",
    "hls": ""
  }
}

The link is OK, but the problem is I can't see this video in my Imgur account, this means it doesn't attached to my account.

Another upload endpoint

Actually, one more upload endpoint can be use, that is https://api.imgur.com/3/image(see here), I tried change:

CURLOPT_URL => 'https://api.imgur.com/3/upload',

to:

CURLOPT_URL => 'https://api.imgur.com/3/image',

It did work, and this time the video successfully attached to my Imgur account, but the point is: No video link is in the response, here is the response json from https://api.imgur.com/3/image endpoint:

{
  "data": {
    "ticket": "33565dc7"
  },
  "success": true,
  "status": 200
}

What does the ticket use for? I never found it on the api doc.

What does lock icon mean?

And I found this in here: enter image description here What does the lock icon mean?

0 Answers
Related