我一直在敲打我的头两天,显然遗漏了一些东西.我对后端/服务器开发有一点想法,希望有人能指出我正确的方向.
问题
谢谢!
package main
import (
"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?
}
Run Code Online (Sandbox Code Playgroud)
参考点
杂项
好的,答案主要位于我的客户端应用程序中(同样,不是 Go),它的 OAuth2 请求中缺少一些方面。(还需要付出一些努力才能使标头针对不同的请求正确。)
我发现的 Reddit OAuth2 流程的最佳信息在这里:http://www.reddit.com/r/redditdev/comments/197x36/using_oauth_to_send_valid_requests/
来自 Reddit 的回复仍然向我询问 ClientID 和 ClientSecret,我确信可以通过适当的 ResponseWriter 来提供这些信息,尽管目前我只是简单地复制/粘贴到弹出窗口中,这样我就可以专注于其他事情!
当我解决这个问题时,我会添加这个答案。
如果有人有兴趣了解更多信息,请随时询问。
再次感谢 TomWilde 和 Elithrar!
| 归档时间: |
|
| 查看次数: |
1896 次 |
| 最近记录: |