•  


Add sample for playlists.list method · youtube/api-samples@e869e95 · GitHub
Skip to content

Commit

Permalink
Add sample for playlists.list method
Browse files Browse the repository at this point in the history
This sample shows how to use the playlists.list method. Use command-line flags to specify the query you want to run.
  • Loading branch information
AndyDiamondstein committed Aug 15, 2017
1 parent 788ebac commit e869e95
Showing 1 changed file with 72 additions and 0 deletions .
72 changes: 72 additions & 0 deletions go/playlists.go
@@ -0,0 +1,72 @@
package main

import (
"flag"
"fmt"
"log"

"google.golang.org/api/youtube/v3"
)

var (
method = flag . String ( "method" , "list" , "The API method to execute. (List is the only method that this sample currently supports." )

channelId = flag . String ( "channelId" , "" , "Retrieve playlists for this channel. Value is a YouTube channel ID." )
hl = flag . String ( "hl" , "" , "Retrieve localized resource metadata for the specified application language." )
maxResults = flag . Int64 ( "maxResults" , 5 , "The maximum number of playlist resources to include in the API response." )
mine = flag . Bool ( "mine" , false , "List playlists for authenticated user's channel. Default: false." )
onBehalfOfContentOwner = flag . String ( "onBehalfOfContentOwner" , "" , "Indicates that the request's auth credentials identify a user authorized to act on behalf of the specified content owner." )
pageToken = flag . String ( "pageToken" , "" , "Token that identifies a specific page in the result set that should be returned." )
part = flag . String ( "part" , "snippet" , "Comma-separated list of playlist resource parts that API response will include." )
playlistId = flag . String ( "playlistId" , "" , "Retrieve information about this playlist." )
)

func playlistsList ( service * youtube. Service , part string , channelId string , hl string , maxResults int64 , mine bool , onBehalfOfContentOwner string , pageToken string , playlistId string ) * youtube. PlaylistListResponse {
call := service . Playlists . List ( part )
if channelId != "" {
call = call . ChannelId ( channelId )
}
if hl != "" {
call = call . Hl ( hl )
}
call = call . MaxResults ( maxResults )
if mine != false {
call = call . Mine ( true )
}
if onBehalfOfContentOwner != "" {
call = call . OnBehalfOfContentOwner ( onBehalfOfContentOwner )
}
if pageToken != "" {
call = call . PageToken ( pageToken )
}
if playlistId != "" {
call = call . Id ( playlistId )
}
response , err := call . Do ()
handleError ( err , "" )
return response
}

func main () {
flag . Parse ()

if * channelId == "" && * mine == false && * playlistId == "" {
log . Fatalf ( "You must either set a value for the channelId or playlistId flag or set the mine flag to 'true'." )
}
client := getClient ( youtube . YoutubeReadonlyScope )

service , err := youtube . New ( client )
if err != nil {
log . Fatalf ( "Error creating YouTube client: %v" , err )
}

response := playlistsList ( service , "snippet,contentDetails" , * channelId , * hl , * maxResults , * mine , * onBehalfOfContentOwner , * pageToken , * playlistId )

for _ , playlist := range response . Items {
playlistId := playlist . Id
playlistTitle := playlist . Snippet . Title

// Print the playlist ID and title for the playlist resource.
fmt . Println ( playlistId , ": " , playlistTitle )
}
}

0 comments on commit e869e95

Please sign in to comment.
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본