Initial structure

This commit is contained in:
Dustin Pianalto
2020-09-25 18:34:48 -08:00
parent 1cdc58a157
commit cab45af1f5
7 changed files with 454 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
package oauth
import (
"net/http"
"os"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
)
func GetClient() *http.Client {
config := &clientcredentials.Config{
ClientID: os.Getenv("TWITTER_API_KEY"),
ClientSecret: os.Getenv("TWITTER_API_SECRET_KEY"),
TokenURL: "https://api.twitter.com/oauth2/token",
}
return config.Client(oauth2.NoContext)
}
+25
View File
@@ -0,0 +1,25 @@
package twitter
import (
"fmt"
"github.com/dghubble/go-twitter/twitter"
oauth "github.com/dustinpianalto/overpass/internal/oauth2"
)
func Connect() *twitter.Client {
httpClient := oauth.GetClient()
return twitter.NewClient(httpClient)
}
func GetTimeline(client *twitter.Client, count int) ([]twitter.Tweet, error) {
tweets, resp, err := client.Timelines.HomeTimeline(&twitter.HomeTimelineParams{
Count: count,
})
if err != nil {
return nil, err
}
fmt.Println(resp)
fmt.Printf("%#v", tweets)
return tweets, nil
}