mirror of
https://github.com/idanoo/NZCovidBot
synced 2025-07-03 04:02:14 +00:00
Pulls from git and posts to discord
This commit is contained in:
parent
d63f121871
commit
b37a425589
12 changed files with 611 additions and 5 deletions
48
internal/nzcovidbot/twitter.go
Normal file
48
internal/nzcovidbot/twitter.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package nzcovidbot
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/dghubble/go-twitter/twitter"
|
||||
"github.com/dghubble/oauth1"
|
||||
)
|
||||
|
||||
type TwitterCredentials struct {
|
||||
ConsumerKey string
|
||||
ConsumerSecret string
|
||||
AccessToken string
|
||||
AccessTokenSecret string
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
httpClient := config.Client(oauth1.NoContext, token)
|
||||
client := twitter.NewClient(httpClient)
|
||||
|
||||
// Verify Credentials
|
||||
verifyParams := &twitter.AccountVerifyParams{
|
||||
SkipStatus: twitter.Bool(true),
|
||||
IncludeEmail: twitter.Bool(true),
|
||||
}
|
||||
|
||||
// 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