Last active
December 15, 2017 03:18
-
-
Save icyflame/7cbc4e70647619f01277542c248b319c to your computer and use it in GitHub Desktop.
go-twitter library - app authentication doesn't fetch user timelines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/dghubble/go-twitter/twitter" | |
"golang.org/x/oauth2" | |
"os" | |
) | |
func main() { | |
config := &oauth2.Config{} | |
token := &oauth2.Token{AccessToken: os.Getenv("ACCESS_CODE")} | |
// OAuth2 http.Client will automatically authorize Requests | |
httpClient := config.Client(oauth2.NoContext, token) | |
// Twitter client | |
client := twitter.NewClient(httpClient) | |
// user show | |
userShowParams := &twitter.UserShowParams{ScreenName: "golang"} | |
user, _, err := client.Users.Show(userShowParams) | |
fmt.Printf("USERS SHOW:\n%+v\n", user) | |
fmt.Printf("Error with Users show: %+v\n", err) | |
// users lookup | |
userLookupParams := &twitter.UserLookupParams{ScreenName: []string{"golang", "gophercon"}} | |
users, _, err := client.Users.Lookup(userLookupParams) | |
fmt.Printf("USERS LOOKUP:\n%+v\n", users) | |
fmt.Printf("Error with users lookup: %+v\n", err) | |
// status show | |
statusShowParams := &twitter.StatusShowParams{} | |
tweet, _, err := client.Statuses.Show(584077528026849280, statusShowParams) | |
fmt.Printf("STATUSES SHOW:\n%+v\n", tweet) | |
fmt.Printf("Error with status show: %+v\n", err) | |
// statuses lookup | |
statusLookupParams := &twitter.StatusLookupParams{ID: []int64{20}, TweetMode: "extended"} | |
tweets, _, err := client.Statuses.Lookup([]int64{573893817000140800}, statusLookupParams) | |
fmt.Printf("STATUSES LOOKUP:\n%+v\n", tweets) | |
fmt.Printf("Error with status lookup %+v\n", err) | |
// oEmbed status | |
statusOembedParams := &twitter.StatusOEmbedParams{ID: 691076766878691329, MaxWidth: 500} | |
oembed, _, err := client.Statuses.OEmbed(statusOembedParams) | |
fmt.Printf("OEMBED TWEET:\n%+v\n", oembed) | |
fmt.Printf("Error with Oembed tweet: %+v\n", err) | |
// user timeline | |
userTimelineParams := &twitter.UserTimelineParams{ScreenName: "_icyflame", Count: 2} | |
tweets, _, err = client.Timelines.UserTimeline(userTimelineParams) | |
fmt.Printf("USER TIMELINE:\n%+v\n", tweets) | |
fmt.Printf("Error with User timeline: %+v\n", err) | |
// search tweets | |
searchTweetParams := &twitter.SearchTweetParams{ | |
Query: "happy birthday", | |
TweetMode: "extended", | |
Count: 3, | |
} | |
search, _, err := client.Search.Tweets(searchTweetParams) | |
fmt.Printf("SEARCH TWEETS:\n%+v\n", search) | |
fmt.Printf("SEARCH METADATA:\n%+v\n", search.Metadata) | |
fmt.Printf("Error with Search: %+v\n", err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment