forked from hoisie/twitterstream
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
|
||
This is an example that uses Twitter oauth PIN | ||
|
||
Get your Twitter Token, and Key from https://dev.twitter.com/apps | ||
|
||
|
||
|
||
|
||
```sh | ||
|
||
go clean && go build | ||
|
||
./twitter_auth --ck=MY_APP_CONSUMER_KEY --cs=MY_APP_SECRET | ||
|
||
|
||
# it will give you a url to go to browser | ||
|
||
|
||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
oauth "github.com/araddon/goauth" | ||
u "github.com/araddon/gou" | ||
"io/ioutil" | ||
) | ||
|
||
/* | ||
Usage: | ||
go clean && go run | ||
./twitter_auth --ck=MY_APP_CONSUMER_KEY --cs=MY_APP_SECRET | ||
*/ | ||
var ( | ||
ck *string = flag.String("ck", "", "Consumer Key") | ||
cs *string = flag.String("cs", "", "Consumer Secret") | ||
goauthcon *oauth.OAuthConsumer | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
goauthcon = &oauth.OAuthConsumer{ | ||
Service: "twitter", | ||
RequestTokenURL: "https://api.twitter.com/oauth/request_token", | ||
AccessTokenURL: "https://api.twitter.com/oauth/access_token", | ||
AuthorizationURL: "https://api.twitter.com/oauth/authorize", | ||
ConsumerKey: *ck, | ||
ConsumerSecret: *cs, | ||
CallBackURL: "oob", | ||
} | ||
|
||
s, rt, err := goauthcon.GetRequestAuthorizationURL() | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
var pin string | ||
|
||
fmt.Printf("Open %s In your browser.\n Allow access and then enter the PIN number\n", s) | ||
fmt.Printf("PIN Number: ") | ||
fmt.Scanln(&pin) | ||
|
||
at := goauthcon.GetAccessToken(rt.Token, pin) | ||
fmt.Printf("\n\n\ttoken=%s secret=%s \n\n\n", at.Token, at.Secret) | ||
r, err := goauthcon.Get("https://api.twitter.com/1.1/account/verify_credentials.json", nil, at) | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
if r != nil && r.Body != nil && r.StatusCode == 200 { | ||
userData, _ := ioutil.ReadAll(r.Body) | ||
if len(userData) > 0 { | ||
jh := u.NewJsonHelper(userData) | ||
fmt.Println(string(jh.PrettyJson())) | ||
} | ||
} else { | ||
fmt.Println(r) | ||
fmt.Println("Twitter verify failed") | ||
} | ||
|
||
} |