Youtube Data API : 用ClientLogin認證

範例說明:

  1. Youtube Data API 測試
  2. 使用ClientLogin
  3. 檔案名稱為 : youtube_test.py
import gdata.youtube.service
 
#顯示取得的資料
def PrintEntryDetails(entry):
  print '\n---------------------------------------\n'
  print 'Video title: \n\t%s' % entry.media.title.text#名稱
  print 'Video published on: \n\t%s ' % entry.published.text#上傳時間
  print 'Video description: \n\t%s' % entry.media.description.text#描述
  print 'Video category: \n\t%s' % entry.media.category[0].text#分類
  print 'Video tags: \n\t%s' % entry.media.keywords.text#標籤
  print 'Video watch page: \n\t%s' % entry.media.player.url
  print 'Video flash player URL: \n\t%s' % entry.GetSwfUrl()
  print 'Video duration: \n\t%s' % entry.media.duration.seconds#片長
  print '\n---------------------------------------\n'
 
#輸入使用者email
email = raw_input('Email:')
#輸入使用者密碼
pw = raw_input('Password:')
#檔案名稱
app_name = 'youtube_test'
#取得使用者所有上傳的檔案
uri = 'http://gdata.youtube.com/feeds/api/users/%s/uploads' % 'default'
#宣告
youtube_service = gdata.youtube.service.YouTubeService()
#使用ClientLogin登入
youtube_service.ClientLogin(email,pw,source = app_name)
 
#向Google傳送資料
feed = youtube_service.GetYouTubeVideoFeed(uri)
 
#印出取得的結果
for entry in feed.entry:
        PrintEntryDetails(entry)
  • 輸出結果
#result
Email:你的Youtube帳號
Password:你的Youtube密碼
Video title: 
    你所上傳的影片.mp4
Video published on: 
    上傳時間
Video description: 
    上傳時所填寫的描述
Video category: 
    選取的類別
Video tags: 
    填寫的標籤
Video watch page: 
    影片網址
Video flash player URL: 
    .swf網址
Video duration: 
    片長

※注意:

  • 本範例會將使用者所有上傳過的檔案都列出來,無論是上傳成功或是失敗。

若想取得更多的資訊請至Youtube Data API