fix creating tweet with media
This commit is contained in:
parent
d55ecabeec
commit
d81d7bb87a
2 changed files with 46 additions and 7 deletions
17
tweet.go
17
tweet.go
|
|
@ -52,17 +52,20 @@ func (s *Scraper) CreateTweet(tweet NewTweet) (*Tweet, error) {
|
||||||
|
|
||||||
req.Header.Set("content-type", "application/json")
|
req.Header.Set("content-type", "application/json")
|
||||||
|
|
||||||
post_medias := map[string]interface{}{
|
media_entities := []map[string]interface{}{}
|
||||||
"media_entities": []string{},
|
|
||||||
"possibly_sensitive": false,
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(tweet.Medias) > 0 {
|
if len(tweet.Medias) > 0 {
|
||||||
var media_ids []string
|
|
||||||
for _, media := range tweet.Medias {
|
for _, media := range tweet.Medias {
|
||||||
media_ids = append(media_ids, strconv.Itoa(media.ID))
|
media_entities = append(media_entities, map[string]interface{}{
|
||||||
|
"media_id": strconv.Itoa(media.ID),
|
||||||
|
"tagged_users": []string{},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
post_medias["media_entities"] = media_ids
|
}
|
||||||
|
|
||||||
|
post_medias := map[string]interface{}{
|
||||||
|
"media_entities": media_entities,
|
||||||
|
"possibly_sensitive": false,
|
||||||
}
|
}
|
||||||
|
|
||||||
variables := map[string]interface{}{
|
variables := map[string]interface{}{
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,42 @@ func TestCreateTweet(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateTweetWithMedia(t *testing.T) {
|
||||||
|
if skipAuthTest {
|
||||||
|
t.Skip("Skipping test due to environment variable")
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
var video *twitterscraper.Media
|
||||||
|
video, err = testScraper.UploadMedia("./photo.jpg")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var photo *twitterscraper.Media
|
||||||
|
photo, err = testScraper.UploadMedia("./video.mp4")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var tweet *twitterscraper.Tweet
|
||||||
|
tweet, err = testScraper.CreateTweet(twitterscraper.NewTweet{
|
||||||
|
Text: "3 more seconds till i get 🖤",
|
||||||
|
Medias: []*twitterscraper.Media{
|
||||||
|
photo,
|
||||||
|
video,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if tweet != nil {
|
||||||
|
testDeleteTweetId = tweet.ID
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDeleteTweet(t *testing.T) {
|
func TestDeleteTweet(t *testing.T) {
|
||||||
if skipAuthTest {
|
if skipAuthTest {
|
||||||
t.Skip("Skipping test due to environment variable")
|
t.Skip("Skipping test due to environment variable")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue