Проблемы с загрузкой видео в твиттер с помощью laravel 11Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Проблемы с загрузкой видео в твиттер с помощью laravel 11

Сообщение Anonymous »

Я пытаюсь загрузить видео в Твиттер в laravel 11, видео имеет размер mp4, 3 МБ и длительность 5 секунд, но с этим видео и со всеми другими видео, а не только с этим, появляется эта ошибка:
Примечание: мои учетные данные приложения и токены пользователя верны

Код: Выделить всё

{
"message": "Failed to upload video",
"error": {
"request": "/1.1/media/upload.json",
"error": "media type unrecognized."
}
}
и это мой код:

Код: Выделить всё

use Abraham\TwitterOAuth\TwitterOAuth;
class TwitterController extends Controller
{
public function uploadVideo(Request $request)
{
// Increase the maximum execution time to 300 seconds (5 minutes)
set_time_limit(300);

// Set your access token details
$userfirst = User::find(Auth()->user()->id);
if ($userfirst->social_type != "twitter") {
$account_id = $userfirst->account_id;
$user = User::where('account_id', $account_id)
->where('social_type', 'twitter')
->where('role', 0)
->first();
if (!$user) {
return response()->json(["message" => "No Twitter account found"], 404);
}
} else {
$user = User::find(Auth()->user()->id);
}

$accessToken = $user->access_token;
$accessTokenSecret = $user->refresh_token;
$userId = $user->social_id;

// Initialize TwitterOAuth with your app credentials and the user's access token
$twitter = new TwitterOAuth(
config('services.twitter.client_id'),
config('services.twitter.client_secret'),
$accessToken,
$accessTokenSecret
);

// Increase the timeout settings
$twitter->setTimeouts(30, 300); // Set the connect timeout to 30 seconds and the request timeout to 300 seconds

// Tell the library we want to use the v1.1 API for media upload
$twitter->setApiVersion('1.1');

// Check if there's a video to upload
if ($request->hasFile('video')) {
$videoFile = $request->file('video');
$videoPath = $videoFile->getPathname();
$videoMimeType = $videoFile->getMimeType();
$videoExtension = $videoFile->getClientOriginalExtension();

// Get the filename without the .tmp extension
$pathInfo = pathinfo($videoPath);
$newVideoPath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . '.' . $videoExtension;

// Rename the file with the correct extension
rename($videoPath, $newVideoPath);

// Upload video
$media = $twitter->upload('media/upload', ['media' => $newVideoPath, 'media_category' => 'tweet_video']);

if (isset($media->media_id_string)) {
return response()->json([
"message" => "Video uploaded successfully",
"media_id" => $media->media_id_string
], 200);
} else {
return response()->json([
"message" => "Failed to upload video",
"error" => $media
], 500);
}
} else {
return response()->json(["message" => "No video file provided"], 400);
}
}
}
примечание: загрузка изображений работает нормально

Подробнее здесь: https://stackoverflow.com/questions/793 ... laravel-11
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»