mirror of
https://github.com/idanoo/NZCovidBot
synced 2025-07-03 04:02:14 +00:00
Update twitter logic, formatting
This commit is contained in:
parent
df3c0b9ed4
commit
458b162295
3 changed files with 19 additions and 53 deletions
|
@ -16,33 +16,23 @@ type TwitterCredentials struct {
|
|||
|
||||
var TwitterCreds TwitterCredentials
|
||||
|
||||
// getClient is a helper function that will return a twitter client
|
||||
// that we can subsequently use to send tweets, or to stream new tweets
|
||||
// this will take in a pointer to a Credential struct which will contain
|
||||
// everything needed to authenticate and return a pointer to a twitter Client
|
||||
// or an error
|
||||
func getClient(creds *TwitterCredentials) (*twitter.Client, error) {
|
||||
// Pass in your consumer key (API Key) and your Consumer Secret (API Secret)
|
||||
config := oauth1.NewConfig(creds.ConsumerKey, creds.ConsumerSecret)
|
||||
// Pass in your Access Token and your Access Token Secret
|
||||
token := oauth1.NewToken(creds.AccessToken, creds.AccessTokenSecret)
|
||||
func postToTwitter() {
|
||||
if TwitterCreds.AccessTokenSecret == "" {
|
||||
return
|
||||
}
|
||||
|
||||
config := oauth1.NewConfig(TwitterCreds.ConsumerKey, TwitterCreds.ConsumerSecret)
|
||||
token := oauth1.NewToken(TwitterCreds.AccessToken, TwitterCreds.AccessTokenSecret)
|
||||
httpClient := config.Client(oauth1.NoContext, token)
|
||||
|
||||
// Twitter client
|
||||
client := twitter.NewClient(httpClient)
|
||||
|
||||
// Verify Credentials
|
||||
verifyParams := &twitter.AccountVerifyParams{
|
||||
SkipStatus: twitter.Bool(true),
|
||||
IncludeEmail: twitter.Bool(true),
|
||||
// Send a Tweet
|
||||
for _, row := range updatedLocations.Locations {
|
||||
_, _, err := client.Statuses.Update(row.TwitterData, nil)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
// we can retrieve the user and verify if the credentials
|
||||
// we have used successfully allow us to log in!
|
||||
user, _, err := client.Accounts.VerifyCredentials(verifyParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Printf("User's ACCOUNT:\n%+v\n", user)
|
||||
return client, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue