本文整理汇总了Golang中github.com/ChimeraCoder/anaconda.TwitterApi.UploadVideoFinalize方法的典型用法代码示例。如果您正苦于以下问题:Golang TwitterApi.UploadVideoFinalize方法的具体用法?Golang TwitterApi.UploadVideoFinalize怎么用?Golang TwitterApi.UploadVideoFinalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ChimeraCoder/anaconda.TwitterApi
的用法示例。
在下文中一共展示了TwitterApi.UploadVideoFinalize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tweet
func (g *gweet) tweet(api *anaconda.TwitterApi,
text string, files []string, lewd bool) (tweetUrl string, err error) {
log.Printf(`Tweeting {"%s", %v, lewd=%v}.`+"\n", text, files, lewd)
var ids string
var data []byte
for _, filePath := range files {
log.Println("Uploading", filePath)
// TODO: refuse files larger than 15mb for vids and 5mb for images
data, err = ioutil.ReadFile(filePath)
if err != nil {
return
}
/*mime*/ meme := http.DetectContentType(data)
log.Println(meme)
if !strings.HasPrefix( /*mime*/ meme, "image") {
var media anaconda.ChunkedMedia
var videoMedia anaconda.VideoMedia
// TODO: do not read entire file to memory
media, err = api.UploadVideoInit(len(data), "video/mp4")
if err != nil {
return
}
chunkIndex := 0
for i := 0; i < len(data); i += 5242879 {
log.Println("Chunk", chunkIndex)
err = api.UploadVideoAppend(media.MediaIDString, chunkIndex,
base64.StdEncoding.EncodeToString(
data[i:int(math.Min(5242879.0, float64(len(data))))],
),
)
if err != nil {
return
}
chunkIndex++
}
videoMedia, err = api.UploadVideoFinalize(media.MediaIDString)
if err != nil {
return
}
ids += videoMedia.MediaIDString
ids += ","
} else {
var media anaconda.Media
media, err = api.UploadMedia(
base64.StdEncoding.EncodeToString(data))
ids += media.MediaIDString
ids += ","
}
if err != nil {
return
}
}
ids = ids[:len(ids)-1]
log.Println("media_ids:", ids)
v := url.Values{}
v.Set("media_ids", ids)
v.Set("possibly_sensitive", strconv.FormatBool(lewd))
tweet, err := api.PostTweet(text, v)
if err != nil {
return
}
tweetUrl = fmt.Sprintf("https://twitter.com/%s/status/%s",
tweet.User.ScreenName, tweet.IdStr)
return
}