2016-07-11 8 views
2

Hier ist mein Code in golang zum instagram apiWenn ich versuche mit der Instagram API eine Verbindung zu oauth2.0 herzustellen, bekomme ich ein 400 - Schlechtes Ergebnis zurück von api.instagram.com. Warum?

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()) 
    } 

und zu verbinden, wenn ich meine Antwort drucken, erhalte ich diese

&{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]})} 

Was geht und wie kann ich es beheben?

+0

Bitte überprüfen Sie diesen Link [http://stackoverflow.com/questions/38136783/get-access-token-using-windows-services-or-console-app-for-instagagram-api/38149095#38149095](http : //stackoverflow.com/questions/38136783/get-access-token-using-windows-services-or-console-app-for-instagram-api/38149095#38149095) –

Antwort

0

Sowohl der Code, den ich übergeben habe, als auch die redirectURI waren falsch. Die redirectURI muss mit der im Autorisierungsschritt verwendeten übereinstimmen.