当我尝试使用 Instagram API 连接到 oauth2.0 时,我从 api.instagram.com 返回了 400 - Bad Result。为什么?
When I try to connect to oauth2.0 with the Instagram API, I get a 400 - Bad Result back from api.instagram.com. Why?
这是我在 golang 中连接到 instagram 的代码api
if resp, err := http.PostForm("https://api.instagram.com/oauth/access_token", url.Values{"client_secret": {appSecret}, "grant_type": {"authorization_code"},
"redirect_uri": {redirectUri}, "client_id": {appId}, "code": {code},
}); err == nil {
log.Info("%s", resp)
} else {
return 500, ctr.ErrorResponse(500, err.Error())
}
当我打印出我的回复时,我得到了这个
&{400 Bad Request %!s(int=400) HTTP/2.0 %!s(int=2) %!s(int=0) map[Content-Length:[114] Expires:[Sat, 01 Jan 2000 00:00:00 GMT] Vary:[Cookie, Accept-Language] Pragma:[no-cache] Cache-Control:[private, no-cache, no-store, must-revalidate] Set-Cookie:[csrftoken=gUnoNsIbM8edetUJO126sp28WZmC1BuO; expires=Mon, 10-Jul-2017 16:45:38 GMT; Max-Age=31449600; Path=/] Content-Language:[en] Date:[Mon, 11 Jul 2016 16:45:38 GMT] Content-Type:[application/json]] {%!s(*http.http2clientStream=&{0xc8201a6f20 0xc82017e380 1 0xc820a26b40 {{0 0} {0xc820d12160 {0 <nil> <nil>} 0 859544035736} 0xc82022e3f0 0xc82000a0e0 <nil> <nil> 0x1f3760} true {10485760 0xc8201a6f68} {4194190 0xc8201a6f78} 114 <nil> 0xc82000b280 0xc820a26ba0 <nil> 0xc820a26c00 true false map[] 0xc820dc6078})} %!s(int64=114) [] %!s(bool=false) map[] %!s(*http.Request=&{POST 0xc82040a180 HTTP/1.1 1 1 map[Content-Type:[application/x-www-form-urlencoded]] {0xc82043b820} 234 [] false api.instagram.com map[] map[] <nil> map[] <nil> <nil>}) %!s(*tls.ConnectionState=&{771 true false 49199 h2 true [0xc8201fcd80 0xc8201fd200] [[0xc8201fcd80 0xc8201fd200 0xc820b28900]] [] [] [203 149 65 158 231 245 216 167 215 32 166 255]})}
这是怎么回事,我该如何解决?
我传入的代码和 redirectURI 都是错误的。 redirectURI 必须与授权步骤中使用的相匹配。
这是我在 golang 中连接到 instagram 的代码api
if resp, err := http.PostForm("https://api.instagram.com/oauth/access_token", url.Values{"client_secret": {appSecret}, "grant_type": {"authorization_code"},
"redirect_uri": {redirectUri}, "client_id": {appId}, "code": {code},
}); err == nil {
log.Info("%s", resp)
} else {
return 500, ctr.ErrorResponse(500, err.Error())
}
当我打印出我的回复时,我得到了这个
&{400 Bad Request %!s(int=400) HTTP/2.0 %!s(int=2) %!s(int=0) map[Content-Length:[114] Expires:[Sat, 01 Jan 2000 00:00:00 GMT] Vary:[Cookie, Accept-Language] Pragma:[no-cache] Cache-Control:[private, no-cache, no-store, must-revalidate] Set-Cookie:[csrftoken=gUnoNsIbM8edetUJO126sp28WZmC1BuO; expires=Mon, 10-Jul-2017 16:45:38 GMT; Max-Age=31449600; Path=/] Content-Language:[en] Date:[Mon, 11 Jul 2016 16:45:38 GMT] Content-Type:[application/json]] {%!s(*http.http2clientStream=&{0xc8201a6f20 0xc82017e380 1 0xc820a26b40 {{0 0} {0xc820d12160 {0 <nil> <nil>} 0 859544035736} 0xc82022e3f0 0xc82000a0e0 <nil> <nil> 0x1f3760} true {10485760 0xc8201a6f68} {4194190 0xc8201a6f78} 114 <nil> 0xc82000b280 0xc820a26ba0 <nil> 0xc820a26c00 true false map[] 0xc820dc6078})} %!s(int64=114) [] %!s(bool=false) map[] %!s(*http.Request=&{POST 0xc82040a180 HTTP/1.1 1 1 map[Content-Type:[application/x-www-form-urlencoded]] {0xc82043b820} 234 [] false api.instagram.com map[] map[] <nil> map[] <nil> <nil>}) %!s(*tls.ConnectionState=&{771 true false 49199 h2 true [0xc8201fcd80 0xc8201fd200] [[0xc8201fcd80 0xc8201fd200 0xc820b28900]] [] [] [203 149 65 158 231 245 216 167 215 32 166 255]})}
这是怎么回事,我该如何解决?
我传入的代码和 redirectURI 都是错误的。 redirectURI 必须与授权步骤中使用的相匹配。