Initial structure
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user