来自HttpWebResponse Instagram的403错误

时间:2015-04-26 07:51:01

标签: c# httpwebrequest instagram http-status-code-403 httpwebresponse

首先抱歉我的英语不好。 任务是使用API​​在instagram中进行身份验证。当我在用户点击&#34之后尝试获取令牌时,确定"我从HttpWebResponse收到403错误,我无法得到我的令牌:(。我不知道该怎么做。请帮助我。当我在浏览器中输入此链接时 - 它没问题

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://instagram.com" + url);
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36";
request.Method = "POST";
request.CookieContainer = cookies;
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
request.Headers.Add("Accept-Encoding: gzip, deflate");
request.Headers.Add("Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4");
request.Headers.Add("Cache-Control:max-age=0");
request.ContentType = "application/x-www-form-urlencoded";
request.Host = "instagram.com";
request.Headers.Add("Origin: https://instagram.com");
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write("csrfmiddlewaretoken=" + par + "&username=LOGIN&password=PASSWORD");
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //403 ERORR

1 个答案:

答案 0 :(得分:0)

只需向API发送用户名/密码对,就无法获得访问令牌!您必须将真实用户引导至Instagram的授权URL,并且在用户成功登录后,Instagram将向您的应用程序发送用于获取访问令牌的代码。

更多信息:https://instagram.com/developer/authentication/