3
このコードは動作します:ログインfacebookで認証するパッケージ「golang.org/x/oauth2」を使用することができません:「REDIRECT_URIパラメータがありません」
func handleFacebookCallback(w http.ResponseWriter, r *http.Request) {
state := r.FormValue("state")
if state != oauthStateString {
fmt.Printf("invalid oauth state, expected '%s', got '%s'\n", oauthStateString, state)
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
return
}
code := r.FormValue("code")
////////////////////////////////////////////////////
Url, err := url.Parse(oauthConf.Endpoint.TokenURL)
if err != nil {
log.Fatal("Parse: ", err)
}
parameters := url.Values{}
parameters.Add("client_id", oauthConf.ClientID)
parameters.Add("client_secret", oauthConf.ClientSecret)
parameters.Add("redirect_uri", "http://localhost:9090/oauth2callback")
parameters.Add("code", code)
Url.RawQuery = parameters.Encode()
resp, err := http.Get(Url.String())
if err != nil {
fmt.Printf("Get: %s\n", err)
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
return
}
defer resp.Body.Close()
しかし、私はとマーカー//////...
以下の部品を交換:
token, err := oauthConf.Exchange(oauth2.NoContext, code)
if err != nil {
fmt.Printf("oauthConf.Exchange() failed with '%s'\n", err)
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
return
}
私が手:
oauthConf.Exchangeは()のOAuth2「で失敗しました:トークンフェッチすることはできません:400不正を10要求の応答:{"エラー":{"メッセージ": "欠落しているredirect_uri パラメータ"、 "タイプ": "OAuthException"、 "コード":191、 "fbtrace_id": "XXXX"}} '
パッケージgolang.org/x/oauth2
はtoken
の場合code
を交換できませんか?