테스트 사이트 - 개발 중인 베타 버전입니다

게시판에 동영상을 올리면 유튜브로 채택완료

사이트 이용 회원이 게시글을 적으면서

자신이 가지고 있는 동영상을 업로드하면,

그 동영상이 자동으로,

사이트 운영 회사에서 운영하는

유튜브 채널로 업로드되게 할수 있을까요?

 

자동으로 될수 없다면

최대한 자동화 근접하게 할수 있는 방법이나

구현에 대한 아이디어나 힌트를 좀 주시면 감사하겠습니다.

 

아무리 머리를 싸매도 답이 안나오네요.

 

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트

회원 동영상 업로드 -> YouTube API 이용하여 채널에 업로드 하면 가능할거 같습니다.

 

참고 1 : https://kminito.tistory.com/5#google_vignette

 

참고 2 : PHP 이용시

 

composer require google/apiclient

 

require_once 'vendor/autoload.php';

function getClient() {     $client = new Google_Client();     $client->setApplicationName("YouTube Upload App");     $client->setScopes([         'https://www.googleapis.com/auth/youtube.upload',         'https://www.googleapis.com/auth/youtube'     ]);     $client->setAuthConfig('path/to/your/client_secret.json');     $client->setAccessType('offline');

    // Load previously authorized credentials from a file.     $credentialsPath = 'path/to/your/credentials.json';     if (file_exists($credentialsPath)) {         $accessToken = json_decode(file_get_contents($credentialsPath), true);         $client->setAccessToken($accessToken);     }

    // If there is no previous token or it's expired.     if ($client->isAccessTokenExpired()) {         // Refresh the token if possible, else fetch a new one.         if ($client->getRefreshToken()) {             $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());         } else {             // Request authorization from the user.             $authUrl = $client->createAuthUrl();             printf("Open the following link in your browser:\n%s\n", $authUrl);             print 'Enter verification code: ';             $authCode = trim(fgets(STDIN));

            // Exchange authorization code for an access token.             $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);             $client->setAccessToken($accessToken);

            // Save the token to a file.             if (!file_exists(dirname($credentialsPath))) {                 mkdir(dirname($credentialsPath), 0700, true);             }             file_put_contents($credentialsPath, json_encode($client->getAccessToken()));         }     }     return $client; }

function uploadVideo($videoPath, $title, $description, $tags, $category = 22) {     try {         $client = getClient();         $youtube = new Google_Service_YouTube($client);

        $snippet = new Google_Service_YouTube_VideoSnippet();         $snippet->setTitle($title);         $snippet->setDescription($description);         $snippet->setTags($tags);         $snippet->setCategoryId($category);

        $status = new Google_Service_YouTube_VideoStatus();         $status->setPrivacyStatus("private"); // or "public" or "unlisted"

        $video = new Google_Service_YouTube_Video();         $video->setSnippet($snippet);         $video->setStatus($status);

        $chunkSizeBytes = 1 * 1024 * 1024;

        $client->setDefer(true);         $insertRequest = $youtube->videos->insert("status,snippet", $video);         $media = new Google_Http_MediaFileUpload(             $client,             $insertRequest,             'video/*',             null,             true,             $chunkSizeBytes         );         $media->setFileSize(filesize($videoPath));

        $status = false;         $handle = fopen($videoPath, "rb");         while (!$status && !feof($handle)) {             $chunk = fread($handle, $chunkSizeBytes);             $status = $media->nextChunk($chunk);         }         fclose($handle);

        $client->setDefer(false);

        if ($status) {             echo "Video uploaded successfully. Video ID: " . $status['id'];         }

        return $status;     } catch (Google_Service_Exception $e) {         echo "An error occurred: " . $e->getMessage();     } catch (Google_Exception $e) {         echo "An error occurred: " . $e->getMessage();     } }

// 사용 예시 $videoPath = 'path/to/your/video.mp4'; $title = '업로드 테스트 동영상'; $description = '이 동영상은 API를 통해 업로드되었습니다.'; $tags = ['테스트', 'API', '업로드'];

uploadVideo($videoPath, $title, $description, $tags);

 

 

 

 

 

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

감사합니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인

전체 질문 목록

🐛 버그신고