两天来我一直在为此绞尽脑汁,显然我遗漏了一些东西。我对后端/服务器开发有点不了解,希望有人能指出我正确的方向。我有一个桌面应用程序(不是 Go),它从 Reddit 发出 OAuth2 请求。我的应用程序中的 OAuth2 工作正常,但是当 Reddit 命中我自己服务器上的重定向 URI 时,流程失败。我猜它正在等待正确的 ResponseWriter 结果,而我十多次无能的尝试都没有奏效。重定向 URI 命中我的服务器和回调函数(如下)然后什么都不做。问题我哪里错了?变量“t”是我的身份验证代码吗?我完成了吗(又名,你是个小丑!)?我可以将 t 的值写入我的非 Go 应用程序并完成吗?还是我错过了一步?注意:代码略有简化。谢谢!package mainimport ( "code.google.com/p/goauth2/oauth" "fmt" "github.com/codegangsta/martini" "io" "net/http")var config = &oauth.Config{ ClientId: CLIENT_ID, ClientSecret: CLIENT_SECRET, Scope: "identify", AuthURL: "https://ssl.reddit.com/api/v1/authorize", TokenURL: "https://ssl.reddit.com/api/v1/access_token", RedirectURL: "http://localhost:3000/reddit_oauth",}func main() { m := martini.Classic() m.Get("/reddit_oauth", handleCallback) m.Run()}func handleCallback(w http.ResponseWriter, r *http.Request) { //Get the code from the response code := r.FormValue("code") // Exchange the received code for a token t := &oauth.Transport{Config: config} t.Exchange(code) // Am I done?}
- 2 回答
- 0 关注
- 244 浏览
添加回答
举报
0/150
提交
取消