Last active
June 1, 2017 11:48
-
-
Save techmaniack/07afd2ff7222140f918a665f2f231a8d to your computer and use it in GitHub Desktop.
go-twitter code examples
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" | |
"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