youtube / api-samples

Code samples for YouTube APIs, including the YouTube Data API, YouTube Analytics API, and YouTube Live Streaming API. The repo contains language-specific directories that contain the samples.
5.5k stars 2.98k forks source link

quickstart.go run error #337

Open Smilenator opened 3 years ago

Smilenator commented 3 years ago

I tried to go by this way: https://developers.google.com/youtube/v3/quickstart/go

When I tried to run the quickstart:

$ go run quickstart.go

I've got the following error:

# command-line-arguments
./quickstart.go:108:32: cannot use part (type string) as type []string in argument to service.Channels.List

Thus quickstart.go isn't working.

FYI go.mod info:

go 1.16

require (
    golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
    golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c
    google.golang.org/api v0.45.0
)
r3k2 commented 3 years ago

same here

willgarrison commented 3 years ago

The methods utilizing the part variable have apparently been updated since the sample code was written. These methods are now expecting a slice.

For me, the simplest solution was just to pass in a slice literal instead of a string.

For example, changing:

call := service.Channels.List(part)

To:

call := service.Channels.List([]string{part})