1

我有一個品牌帳戶,我使用谷歌應用腳​​本通過Youtube Data API v3將url上傳到YouTube。這是我的代碼:如何使用Google Apps腳本將視頻上傳到Youtube?

function YouTubeAPI() 
{ 
    var url = {URL VIDEO}; 
    var file = UrlFetchApp.fetch(url).getBlob(); 
    Logger.log(file.getName()); 
    var snippet = { 
    "snippet": { 
    "title": "Summer vacation in California", 
    "description": "Had a great time surfing in Santa Cruz", 
    "tags": ["surfing", "Santa Cruz"], 
    "categoryId": "22"},"status": {"privacyStatus": "private"}}; 
    YouTube.Videos.insert(snippet, 'snippet,status', file) 
} 

的迴應是「未授權」,我查谷歌控制檯啓用,並在腳本也使YouTube數據API。

感謝您的幫助!

回答

0

您首先需要授權您的帳戶擁有使用API​​的權限。 有關更多信息和實施,請參閱this link

+0

是的,我檢查這個,但不行。 orthers的服務,如果工作,例如,搜索,或列表等,但不工作上傳 –

+0

@JuanAcosta檢查我的代碼在這裏上傳youtube,它的工作:https://github.com/sangnvus/2015SUMJS01/blob/主/ WIP/Sources/FlyAwayPlus/FlyAwayPlus /腳本/ youtube-upload.js –

+0

謝謝,但也許你有谷歌應用腳​​本的代碼? –

0

嘗試使用code below。此示例代碼會查找用戶的上傳內容,然後通過附加字符串來更新最新上傳的說明。

/** 
* This sample finds the active user's uploads, then updates the most recent 
* upload's description by appending a string. 
*/ 
function updateVideo() { 
    // 1. Fetch all the channels owned by active user 
    var myChannels = YouTube.Channels.list('contentDetails', {mine: true}); 
    // 2. Iterate through the channels and get the uploads playlist ID 
    for (var i = 0; i < myChannels.items.length; i++) { 
    var item = myChannels.items[i]; 
    var uploadsPlaylistId = item.contentDetails.relatedPlaylists.uploads; 

    var playlistResponse = YouTube.PlaylistItems.list('snippet', { 
     playlistId: uploadsPlaylistId, 
     maxResults: 1 
    }); 

    // Get the videoID of the first video in the list 
    var video = playlistResponse.items[0]; 
    var originalDescription = video.snippet.description; 
    var updatedDescription = originalDescription + ' Description updated via Google Apps Script'; 

    video.snippet.description = updatedDescription; 

    var resource = { 
     snippet: { 
     title: video.snippet.title, 
     description: updatedDescription, 
     categoryId: '22' 
     }, 
     id: video.snippet.resourceId.videoId 
    }; 
    YouTube.Videos.update(resource, 'id,snippet'); 
    } 
} 

欲瞭解更多信息,請下載演示應用程序:https://github.com/youtube/api-samples

相關問題