Created
December 28, 2018 00:00
-
-
Save Adron/d7376f729468f4dff53fa6c7ca28532e to your computer and use it in GitHub Desktop.
Findem Functionality for looking up a list of Twitter Accounts via the Twitter API for the Twitz app.
This file contains 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
var findemCmd = &cobra.Command{ | |
Use: "findem", | |
Short: "A brief description of your command", | |
Long: `A longer description that spans multiple lines and likely contains examples | |
and usage of using your command. For example: | |
Cobra is a CLI library for Go that empowers applications. | |
This application is a tool to generate the needed files | |
to quickly create a Cobra application.`, | |
Run: func(cmd *cobra.Command, args []string) { | |
fmt.Println("Starting Twitter Information Retrieval.") | |
completedTwitterList := buildTwitterList() | |
fmt.Printf("Getting Twitter details for: \n%s", completedTwitterList) | |
accessToken, err := getBearerToken(viper.GetString("consumer_api_key"), viper.GetString("consumer_api_secret")) | |
check(err) | |
config := &oauth2.Config{} | |
token := &oauth2.Token{AccessToken: accessToken} | |
// OAuth2 http.Client will automatically authorize Requests | |
httpClient := config.Client(context.Background(), token) | |
// Twitter client | |
client := twitter.NewClient(httpClient) | |
// users lookup | |
userLookupParams := &twitter.UserLookupParams{ScreenName: completedTwitterList} | |
users, _, _ := client.Users.Lookup(userLookupParams) | |
fmt.Printf("\n\nUsers:\n%+v\n", users) | |
howManyUsersFound := len(users) | |
fmt.Println(howManyUsersFound) | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment