Skip to content

Commit

Permalink
"Updating samples to reflect recent changes."
Browse files Browse the repository at this point in the history
  • Loading branch information
ulukaya committed Jun 5, 2014
1 parent 05e8907 commit 104c2fe
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion go/my_uploads.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ func main() {
log.Fatalf("Error creating YouTube client: %v", err)
}

// Starting making YouTube API calls
// Start making YouTube API calls.
// Call the channels.list method. Set the mine parameter to true to
// retrieve the playlist ID for uploads to the authenticated user's
// channel.
call := service.Channels.List("contentDetails").Mine(true)

response, err := call.Do()
if err != nil {
// The channels.list method call returned an error.
log.Fatalf("Error making API call to list channels: %v", err.Error())
}

for _, channel := range response.Items {
playlistId := channel.ContentDetails.RelatedPlaylists.Uploads
// Print the playlist ID for the list of uploaded videos.
fmt.Printf("Videos in list %s\r\n", playlistId)

nextPageToken := ""
for {
// Call the playlistItems.list method to retrieve the
// list of uploaded videos. Each request retrieves 50
// videos until all videos have been retrieved.
playlistCall := service.PlaylistItems.List("snippet").
PlaylistId(playlistId).
MaxResults(50).
Expand All @@ -43,6 +51,7 @@ func main() {
playlistResponse, err := playlistCall.Do()

if err != nil {
// The playlistItems.list method call returned an error.
log.Fatalf("Error fetching playlist items: %v", err.Error())
}

Expand All @@ -52,6 +61,8 @@ func main() {
fmt.Printf("%v, (%v)\r\n", title, videoId)
}

// Set the token to retrieve the next page of results
// or exit the loop if all results have been retrieved.
nextPageToken = playlistResponse.NextPageToken
if nextPageToken == "" {
break
Expand Down

0 comments on commit 104c2fe

Please sign in to comment.