Instagram Login + Follower

by iproxy - 28-12-2015, 05:14 AM
Novice
Posts:
42
Joined:
Dec 2015
Likes:
0
Credits:
-1
Reputation:
0
1 Year of Service
#1
OP
Posted: 28-12-2015, 05:14 AM
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, @"(?<=""csrf_token"":"")(.*?)(?="")").Value;
       string id = Regex.Match(request, @"(?<=""id"":"")(.*?)(?="")").Value;
       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, @"(?<=""csrf_token"":"")(.*?)(?="")").Value;
       do_Login(username, password, csrf_token);
   }
}
Pro CSGO Cheater
Posts:
738
Joined:
Jan 2015
Likes:
56
Credits:
208
Reputation:
48
2 Years of Service
#2
Posted: 31-12-2015, 04:06 AM
Probably should of added you need the Instagram dll
[Image: 2lnzmZm.gif]
Nan Ihier Gelair Mordor
Posts:
2,622
Joined:
Jan 2015
Likes:
279
Credits:
7,809
Reputation:
89
Developer
2 Years of Service
#3
Posted: 23-01-2016, 02:15 PM
This is C# and not C/C++.
Do not let your difficulties fill you with anxiety, after all it is only in the darkest nights that stars shine more brightly. - Ali(a.s)

Developer( PHP, Python, C++, HTML+CSS, JS I am available for Hire. Message Me for details.
Junior Member
Posts:
57
Joined:
Jan 2016
Likes:
5
Credits:
32
Reputation:
-4
1 Year of Service
#4
Posted: 24-01-2016, 01:34 AM (This post was last modified: 24-01-2016, 01:35 AM by bitm0de.)
(31-12-2015, 04:06 AM)Torchwood Wrote: Probably should of added you need the Instagram dll

I don't know what you're talking about because you really don't. The class is a wrapper for everything contained already in the .NET BCL... :S Did you bother looking at the code or only just assume that there were missing dependencies??

(23-01-2016, 02:15 PM)Sozin Wrote: This is C# and not C/C++.

Exactly -- why can't people realize this? I've seen people do it on too many forums thinking that C# belongs with C/C++/Obj-C.
Pro CSGO Cheater
Posts:
738
Joined:
Jan 2015
Likes:
56
Credits:
208
Reputation:
48
2 Years of Service
#5
Posted: 24-01-2016, 02:39 AM (This post was last modified: 24-01-2016, 02:41 AM by Mat.)
(24-01-2016, 01:34 AM)bitm0de Wrote:
(31-12-2015, 04:06 AM)Torchwood Wrote: Probably should of added you need the Instagram dll

I don't know what you're talking about because you really don't. The class is a wrapper for everything contained already in the .NET BCL... :S Did you bother looking at the code or only just assume that there were missing dependencies??

(23-01-2016, 02:15 PM)Sozin Wrote: This is C# and not C/C++.

Exactly -- why can't people realize this? I've seen people do it on too many forums thinking that C# belongs with C/C++/Obj-C.

Missing dependencies due to when I opened up the source, "instagram.dll" is missing, after checking around the code provided - there was no dll, I presume this was fixed/updated...

EDIT: Not sure why it's requiring an instagram.dll since it's not using it.
[Image: 2lnzmZm.gif]
Junior Member
Posts:
57
Joined:
Jan 2016
Likes:
5
Credits:
32
Reputation:
-4
1 Year of Service
#6
Posted: 24-01-2016, 02:48 AM (This post was last modified: 24-01-2016, 02:51 AM by bitm0de.)
(24-01-2016, 02:39 AM)Torchwood Wrote:
(24-01-2016, 01:34 AM)bitm0de Wrote:
(31-12-2015, 04:06 AM)Torchwood Wrote: Probably should of added you need the Instagram dll

I don't know what you're talking about because you really don't. The class is a wrapper for everything contained already in the .NET BCL... :S Did you bother looking at the code or only just assume that there were missing dependencies??

(23-01-2016, 02:15 PM)Sozin Wrote: This is C# and not C/C++.

Exactly -- why can't people realize this? I've seen people do it on too many forums thinking that C# belongs with C/C++/Obj-C.

Missing dependencies due to when I opened up the source, "instagram.dll" is missing, after checking around the code provided - there was no dll, I presume this was fixed/updated...

EDIT: Not sure why it's requiring an instagram.dll since it's not using it.

There is no "This post was last modified" line in the first post. The thread was never modified and never required any external shared library. :S

The code by itself is atrocious though.
Code:
StreamReader reader = new StreamReader(postResponse.GetResponseStream());

Last line of a function for instance, StreamReader is never disposed, it's a local too. The variable isn't even used..
Pro CSGO Cheater
Posts:
738
Joined:
Jan 2015
Likes:
56
Credits:
208
Reputation:
48
2 Years of Service
#7
Posted: 24-01-2016, 02:50 AM
(24-01-2016, 02:48 AM)bitm0de Wrote:
(24-01-2016, 02:39 AM)Torchwood Wrote:
(24-01-2016, 01:34 AM)bitm0de Wrote:
(31-12-2015, 04:06 AM)Torchwood Wrote: Probably should of added you need the Instagram dll

I don't know what you're talking about because you really don't. The class is a wrapper for everything contained already in the .NET BCL... :S Did you bother looking at the code or only just assume that there were missing dependencies??

(23-01-2016, 02:15 PM)Sozin Wrote: This is C# and not C/C++.

Exactly -- why can't people realize this? I've seen people do it on too many forums thinking that C# belongs with C/C++/Obj-C.

Missing dependencies due to when I opened up the source, "instagram.dll" is missing, after checking around the code provided - there was no dll, I presume this was fixed/updated...

EDIT: Not sure why it's requiring an instagram.dll since it's not using it.

There is no "This post was last modified" line in the first post. The thread was never modified.


Didn't really realise that, jumped straight down to your reply.
[Image: 2lnzmZm.gif]
Newbie
Posts:
10
Joined:
Jan 2017
Likes:
0
Credits:
10
Reputation:
0
#8
Posted: 09-01-2017, 09:52 AM
Thanks, i hope u could update your theard with the .dll file too
Lurker
Posts:
1
Joined:
Jan 2017
Likes:
0
Credits:
1
Reputation:
0
#9
Posted: 22-01-2017, 04:31 AM
Is it working right now?
Novice
Posts:
22
Joined:
Jan 2017
Likes:
0
Credits:
6
Reputation:
0
#10
Posted: 29-01-2017, 01:13 PM
thanks i need this for my program =D
The last reply on this thread is older than a month. Please do not unnecessarily bump it.
Register an account or login to reply
Create an account
Create a free account today and start posting right away. It only takes a few seconds.
Login
Log into an existing account.
1 Guest(s)