0
我試圖通過示例在IG文檔中實現服務器端身份驗證,但遇到了麻煩。 當我正在做我的請求,我已經得到狀態302發現的響應,並且在標題位置我沒有新的代碼重定向url,但是如果我在瀏覽器中做同樣的事情,一切都好。Instagram api服務器端身份驗證asp.net mvc
這裏是我的代碼和例子:
public JsonResult InstagramTeaser()
{
try
{
var clientId = Configuration.AuthKeys.InstagramOAuthClientId;
var clientSecret = Configuration.AuthKeys.InstagramOAuthClientSecret;
var redirectUrl = "http://localhost";
var uri = $"http://api.instagram.com/oauth/authorize/?client_id={clientId}&redirect_uri={redirectUrl}&response_type=code";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.AllowAutoRedirect = false;
string redirUrl = String.Empty;
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
{
int status = (int)response.StatusCode; // 302 Found
redirUrl = response.Headers[HttpResponseHeader.Location]; // And here I'm getting my old uri
}
return Json(redirUrl, JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
return Json(e.Message, JsonRequestBehavior.AllowGet);
}
}