J7mbo / twitter-api-php

The simplest PHP Wrapper for Twitter API v1.1 calls
MIT License
1.82k stars 802 forks source link

Error when Upload file to twitter = chunk method #253

Open vitqst opened 6 years ago

vitqst commented 6 years ago
$file = fopen($this->filePath, "r");
while (! feof($file)) {
            $chunk = fread($file, 1048576);

            $dataRequest = [
                "command" => "APPEND",
                "media_id" => $this->mediaId,
                "media_data" => base64_encode($chunk),
                "segment_index" => $segmentId,
            ];

            $this->twitter->request(self::API_MEDIA_ENDPOINT_URL, "POST", $dataRequest);

            if (
                $this->twitter->getHttpStatusCode() < 200 ||
                $this->twitter->getHttpStatusCode() > 299 ||
                $this->twitter->getHttpStatusCode() === 204 // No Content
            ) {
                $this->print("status_code : " . $this->twitter->getHttpStatusCode());
                $this->print($this->twitter->getPostfields());
                exit;
            }

            $segmentId++;
            $bytesSent = ftell($file);
            printf("\n%s of %s bytes uploaded\n", $bytesSent, $this->fileSize);
}    

this is my code, i think request don't have "multipart/form-data"