Skip to content

Instantly share code, notes, and snippets.

@techmaniack
Last active June 1, 2017 11:48
Show Gist options
  • Save techmaniack/07afd2ff7222140f918a665f2f231a8d to your computer and use it in GitHub Desktop.
Save techmaniack/07afd2ff7222140f918a665f2f231a8d to your computer and use it in GitHub Desktop.
go-twitter code examples
package main
import (
"fmt"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
)
func main() {
consumerKey := "KEY"
consumerSecret := "SECRET"
accessToken := "TOKEN"
accessSecret := "SECRET"
config := oauth1.NewConfig(consumerKey, consumerSecret)
token := oauth1.NewToken(accessToken, accessSecret)
// OAuth1 http.Client will automatically authorize Requests
httpClient := config.Client(oauth1.NoContext, token)
// Twitter client
client := twitter.NewClient(httpClient)
// Verify Credentials
verifyParams := &twitter.AccountVerifyParams{
IncludeEmail: twitter.Bool(true),
}
user, _, _ := client.Accounts.VerifyCredentials(verifyParams)
fmt.Printf("User's Name:%+v\n", user.ScreenName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment