• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

C# Instagram Login + Follow

Status
Not open for further replies.

dEEpEst

☣☣ In The Depths ☣☣
Staff member
Administrator
Super Moderator
Hacker
Specter
Crawler
Shadow
Joined
Mar 29, 2018
Messages
13,862
Solutions
4
Reputation
32
Reaction score
45,552
Points
1,813
Credits
55,350
‎7 Years of Service‎
 
56%
[HIDE-THANKS]

Code:
>using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using System.Diagnostics;
class InstagramWrapper
{
   private CookieCollection loginCookies;
   public WebProxy proxy = null;
   private void do_Login(string Username, string Password, string CSRF)
   {
       byte[] bytes = ASCIIEncoding.UTF8.GetBytes("username=" + Username + "&password=" + Password);
       HttpWebRequest postReq = (HttpWebRequest)WebRequest.Create("https://instagram.com/accounts/login/ajax/");
       WebHeaderCollection postHeaders = postReq.Headers;
       postReq.Proxy = proxy;
       postReq.Method = "POST";
       postReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0";
       postReq.Accept = "*/*";
       postHeaders.Add("Accept-Language", "it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3");
       postHeaders.Add("Accept-Encoding", "gzip, deflate");
       postReq.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
       postHeaders.Add("X-Instagram-AJAX", "1");
       postHeaders.Add("X-CSRFToken", CSRF);
       postHeaders.Add("X-Requested-With", "XMLHttpRequest");
       postReq.Referer = "https://instagram.com/accounts/login/";
       postReq.ContentLength = bytes.Length;
       var cookies = new CookieContainer();
       cookies.Add(new Cookie("csrftoken", CSRF) { Domain = "instagram.com" });
       postReq.CookieContainer = cookies;
       postReq.KeepAlive = true;
       postHeaders.Add("Pragma", "no-cache");
       postHeaders.Add("Cache-Control", "no-cache");
       Stream postStream = postReq.GetRequestStream();
       postStream.Write(bytes, 0, bytes.Length);
       postStream.Close();
       HttpWebResponse postResponse;
       postResponse = (HttpWebResponse)postReq.GetResponse();
       loginCookies = postResponse.Cookies;
       StreamReader reader = new StreamReader(postResponse.GetResponseStream());
   }
   private void doFollow(string profilelink, string followerlink, string CSRF)
   {
       HttpWebRequest postReq = (HttpWebRequest)WebRequest.Create(followerlink);
       WebHeaderCollection postHeaders = postReq.Headers;
       postReq.Proxy = proxy;
       postReq.Method = "POST";
       postReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36";
       postReq.Accept = "*/*";
       postReq.Referer = profilelink;
       postHeaders.Add("Accept-Language", "en-US,en;q=0.8,ro;q=0.6,de;q=0.4,es;q=0.2,ms;q=0.2");
       postHeaders.Add("Accept-Encoding", "gzip, deflate");
       postHeaders.Add("X-Instagram-AJAX", "1");
       postHeaders.Add("X-CSRFToken", CSRF);
       postHeaders.Add("X-Requested-With", "XMLHttpRequest");
       var cookies = new CookieContainer();
       cookies.Add(loginCookies);
       cookies.Add(new Cookie("csrftoken", CSRF) { Domain = "instagram.com" });
       postReq.CookieContainer = cookies;
       postReq.KeepAlive = true;
       postHeaders.Add("Pragma", "no-cache");
       postHeaders.Add("Cache-Control", "no-cache");
       Stream postStream = postReq.GetRequestStream();
       postStream.Close();
       HttpWebResponse postResponse;
       postResponse = (HttpWebResponse)postReq.GetResponse();
       StreamReader reader = new StreamReader(postResponse.GetResponseStream());

   }
   private string getRequest(string url)
   {
       var request = (HttpWebRequest)WebRequest.Create(url);
       request.Proxy = proxy;
       using (var response = request.GetResponse())
       {
           using (var reader = new StreamReader(response.GetResponseStream()))
           {
               return reader.ReadToEnd();
           }
       }
   }
   public void Follow(string profilelink)
   {
       string request = getRequest(profilelink);
       string csrf_token = Regex.Match(request, @"(?        string id = Regex.Match(request, @"(?        doFollow(profilelink, string.Format("https://instagram.com/web/friendships/{0}/follow/", id), csrf_token);
   }
   public void Login(string username, string password)
   {
       string test = getRequest("https://instagram.com/accounts/login/");
       string csrf_token = Regex.Match(test, @"(?        do_Login(username, password, csrf_token);
   }
}
[/HIDE-THANKS]

 
Status
Not open for further replies.
Back
Top