Using Api key I was able to fetch the videos in a playlist from Api Explorer .
(使用Api键,我可以从Api Explorer中获取播放列表中的视频。)
Execute without OAuth fetched the results json. (没有OAuth的执行将获取结果json。)
Here is the link. (链接在这里。)
https://developers.google.com/apis-explorer/?hl=en_US#p/youtube/v3/youtube.playlistItems.list?part=snippet&playlistId=PLHyTuYqPkZCzt7mWZ4hmmrRdjLJiw6O2T&_h=2&
(https://developers.google.com/apis-explorer/?hl=zh_CN#p/youtube/v3/youtube.playlistItems.list?part=snippet&playlistId=PLHyTuYqPkZCzt7mWZ4hmmrRdjLJiw6O2T&_h=2&)
Implementing the same call using Go on App engine fails with below error:
(使用Go on App引擎实施相同的调用失败,并显示以下错误:)
Get https://www.googleapis.com/youtube/v3/playlistItems?alt=json&part=snippet&playlistId=PLHyTuYqPkZCzt7mWZ4hmmrRdjLJiw6O2T: http.DefaultTransport and http.DefaultClient are not available in App Engine. See https://cloud.google.com/appengine/docs/go/urlfetch/
Here is the code I use:
(这是我使用的代码:)
import (
"net/http"
"code.google.com/p/google-api-go-client/googleapi/transport"
"code.google.com/p/google-api-go-client/youtube/v3"
"log"
)
var service *youtube.Service
func init() {
var err error
log.Println("Apikey = ", apiKey)
client := &http.Client{Transport: &transport.APIKey{Key: apiKey}}
service, err = youtube.New(client)
if err != nil {
log.Println("ERROR in creating youtube New client ", err)
}
var items *youtube.PlaylistItemListResponse
if items, err = service.PlaylistItems.List("snippet").PlaylistId("PLHyTuYqPkZCzt7mWZ4hmmrRdjLJiw6O2T").Do(); err != nil {
log.Println("Error in fetching playlist items ", err) //this line shows the error
}
log.Println(Jsonify(items))
}
As of now, I run my code on local dev server ie goapp serve
(到目前为止,我在本地开发服务器上运行我的代码,即goapp serve)
What is missing?
(缺什么?)
How do I fetch youtube playlist videos using v3 api and ApiKey? (如何使用v3 api和ApiKey提取youtube播放列表视频?)
ask by suman j translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…