Youtube Data API:Upload

範例說明:

import gdata.youtube.service
import gdata.media
 
#設定影片本身的屬性
media_group = gdata.media.Group(
  title = gdata.media.Title(text = 'Test Video'), #標題
  description = gdata.media.Description(text = 'this is upload with python'), #描述
  keywords = gdata.media.Keywords(text = 'youtube-api,python'), #關鍵字
  category = gdata.media.Category(text = 'Autos'), #類別
  private = gdata.media.Private() #隱私屬性
  )
 
video_entry = gdata.youtube.YouTubeVideoEntry(media = media_group) #存入設定
video_file_at = '\pat\to\your_video' #影片位置
 
#使用ClientLogin中的ProgrammaticLogin()以便傳送developer_key
yt_service = gdata.youtube.service.YouTubeService()
yt_service.email = raw_input('Email:')
yt_service.password = raw_input('Password:')
yt_service.developer_key = 'this_is_your_developer_key'
yt_service.ProgrammaticLogin()
 
new_entry = yt_service.InsertVideoEntry(video_entry,video_file_at) #上傳影片

結果可使用Youtube Data API : 用ClientLogin認證的範例查詢

關於gdata.media.Group可設定的屬性請至:
'http://gdata-python-client.googlecode.com/hg/pydocs/gdata.media.html'內查看

※注意事項

  • 必須傳遞developer_key作為參數,否則會出現403 forbidden(權限不足)
  • 不設定private屬性時,private屬性默認為false(也就是public)