Created
July 7, 2017 09:15
-
-
Save aki-lua87/cd862f1d4a2e1e633424964b01675929 to your computer and use it in GitHub Desktop.
GAE/Goでanacondaを利用した認証 ref: http://qiita.com/aki_lua87/items/718e999fc37b252d1c53
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
go get "github.com/ChimeraCoder/anaconda" | |
go get "github.com/garyburd/go-oauth/oauth" | |
go get "google.golang.org/appengine" |
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 credential *oauth.Credentials | |
func GetRequestTokenHandler(w http.ResponseWriter, r *http.Request) { | |
ctx := appengine.NewContext(r) | |
http.DefaultClient.Transport = &urlfetch.Transport{Context: ctx} | |
anaconda.SetConsumerKey("consumerKey") | |
anaconda.SetConsumerSecret("consumerSecret") | |
url, tmpCred, err := anaconda.AuthorizationURL("GetAccessTokenHandlerが呼ばれるURL") | |
if err != nil { | |
return | |
} | |
credential = tmpCred | |
http.Redirect(w, r, url, http.StatusFound) | |
} |
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
func GetAccessTokenHandler(w http.ResponseWriter, r *http.Request) { | |
ctx := appengine.NewContext(r) | |
http.DefaultClient.Transport = &urlfetch.Transport{Context: ctx} | |
c, _, err := anaconda.GetCredentials(credential, r.URL.Query().Get("oauth_verifier")) | |
if err != nil { | |
return | |
} | |
api := anaconda.NewTwitterApi(c.Token, c.Secret) | |
// TEST POST | |
api.PostTweet("test tweet", nil) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment