added DeleteScheduledTweet
This commit is contained in:
parent
7b2215391a
commit
c862968cdd
2 changed files with 55 additions and 1 deletions
43
schedule.go
43
schedule.go
|
|
@ -1,6 +1,10 @@
|
|||
package twitterscraper
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -140,3 +144,42 @@ func (s *Scraper) FetchScheduledTweets() ([]*ScheduledTweet, error) {
|
|||
tweets := timeline.parseTweets()
|
||||
return tweets, nil
|
||||
}
|
||||
|
||||
// DeleteScheduledTweet removes tweet from scheduled.
|
||||
func (s *Scraper) DeleteScheduledTweet(id string) error {
|
||||
req, err := s.newRequest("POST", "https://twitter.com/i/api/graphql/CTOVqej0JBXAZSwkp1US0g/DeleteScheduledTweet")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("content-type", "application/json")
|
||||
|
||||
variables := map[string]interface{}{
|
||||
"scheduled_tweet_id": id,
|
||||
}
|
||||
|
||||
body := map[string]interface{}{
|
||||
"variables": variables,
|
||||
"queryId": "CTOVqej0JBXAZSwkp1US0g",
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(body)
|
||||
req.Body = io.NopCloser(bytes.NewReader(b))
|
||||
|
||||
var response struct {
|
||||
Data struct {
|
||||
Status string `json:"scheduledtweet_delete"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
err = s.RequestAPI(req, &response)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if response.Data.Status == "Done" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("scheduled tweet wasn't removed")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue