How To Login To Instagram Using The API In VB.NET

instagram picture
Instagram is a photo and video sharing app for smartphones, we can call it a social network. As I said It's a smartphone app but you can view photos, like photos, comment on photos and follow/unfollow users via their website from computer also there are more than 10 popular websites where you can view photos, like photos, comment on photos and follow/unfollow users, browse hashtags and view stats they use the API to do the works.

Without much talk let's get into it..

Remember you're just going to make a Instagram Login, you won't be able to view photos or do anything. You need two textbox and a button you can also add two labels to make it look good. The textbox1 is for username and textbox2 is for password.

Instagram Login form preview

Time for some codes...

Required Namespaces :
Imports System.IO
Imports System.Net
Imports System.Text

Functions(We need two functions) :
  
 Dim CC As New CookieContainer
    Dim RQ As HttpWebRequest
    Dim RP As HttpWebResponse
    Public Function GetResponse(ByVal url As String, ByVal referer As String) As String
        RQ = CType(HttpWebRequest.Create(url), HttpWebRequest)
        RQ.CookieContainer = CC

        If referer <> "" Then
            RQ.Referer = referer
        End If

        RP = CType(RQ.GetResponse(), HttpWebResponse)

        Return New StreamReader(RP.GetResponseStream()).ReadToEnd()
    End Function

    Public Function GetResponse(ByVal url As String, ByVal post As String, ByVal referer As String) As String
        RQ = CType(HttpWebRequest.Create(url), HttpWebRequest)
        RQ.Method = "POST"
        RQ.CookieContainer = CC
        RQ.UserAgent = "AppleWebKit/537.36 (KHTML, like Gecko) Mozilla/5.0 (Windows NT 6.1) Chrome/28.0.1468.0 Safari/537.36"

        If referer <> "" Then
            RQ.Referer = referer
        End If

        Dim byteArr() As Byte = Encoding.Default.GetBytes(post)
        RQ.ContentLength = byteArr.Length

        Dim dataStream As Stream = RQ.GetRequestStream()
        dataStream.Write(byteArr, 0, byteArr.Length)

        RP = CType(RQ.GetResponse(), HttpWebResponse)

        Return New StreamReader(RP.GetResponseStream()).ReadToEnd()
    End Function

This code is for your login button :
Dim html As String = GetResponse("https://instagram.com/accounts/login/", "")
        Dim token As String = html.Substring(html.IndexOf("csrfmiddlewaretoken")).Split(""""c)(2)
        Dim username As String = TextBox1.Text
        Dim password As String = TextBox2.Text

        Dim S_B As New StringBuilder
        S_B.Append("csrfmiddlewaretoken=" & token)
        S_B.Append("&username=" & username)
        S_B.Append("&password=" & password)

        html = GetResponse("https://instagram.com/accounts/login/", S_B.ToString, "https://instagram.com/accounts/login/")

        If html.Contains("""username"":""" & username) Then
            MsgBox("Successfully Logged In", MessageBoxIcon.Information)
        ElseIf html.Contains("Please enter a correct username and password.") Then
            MsgBox("Invalid Username or Password", MessageBoxIcon.Error)
        Else
            MsgBox("Unable Login Error", MessageBoxIcon.Error)
        End If


Now run the program and test it..

If you enter correct login credentials you will get this message :

How To Login To Instagram Using The API In VB.NET

I am looking to develop a Instagram picture view if everything goes well I will let you all know. Follow me on Instagram @54j33dh4.

How To Make A Custom Button In VB.NET

we all know how to make custom buttons using images or DLLs but this tutorial is totally different in this tutorial i will be teaching you how to make a custom button without using images or dlls .

so lets get started 

as usual open your visual basic 2008 or  visual basic 2010 and create a new windows application and name it whatever you want and go to the form and add a button and thats it with the GUI and go to code and lets add the custom button function

i am going to use a function , i call it "shimscustombuttonfunction"
 Public Sub shimscustombuttonfunction(ByVal aControl As Control, ByVal Color1 As Color, ByVal Color2 As Color, _
        Optional ByVal mode As System.Drawing.Drawing2D.LinearGradientMode = Drawing2D.LinearGradientMode.Vertical)

        Dim bmp As New Bitmap(aControl.Width, aControl.Height)
        Dim g As Graphics = Graphics.FromImage(bmp)
        Dim Rect1 As New RectangleF(0, 0, aControl.Width, aControl.Height)

        Dim lineGBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color1, Color2, mode)
        g.FillRectangle(lineGBrush, Rect1)

        aControl.BackgroundImage = bmp
        g.Dispose()
    End Sub
now lets add two events for the button , go to the form and double click button and add this code . i am using green because thats my favourite color and you can just add any color to it simply change the (button1,color.lightgreen,color.green) and your done .

Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
        shimscustombuttonfunction(Button1, Color.LightGreen, Color.Green)
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
        Button1.BackgroundImage = Nothing
    End Sub
so finally the custom button will work like this


i have just added two events mouse enter and mouse leave and you can add many more events like mouse click,mouse down,mouse up,mouse hover and mouse move

here is the full source code
'Author : Mohamed Shimran
'Blog : http://ultimateprogrammingtutorials.blogspot.com
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Public Sub shimscustombuttonfunction(ByVal aControl As Control, ByVal Color1 As Color, ByVal Color2 As Color, _
        Optional ByVal mode As System.Drawing.Drawing2D.LinearGradientMode = Drawing2D.LinearGradientMode.Vertical)

        Dim bmp As New Bitmap(aControl.Width, aControl.Height)
        Dim g As Graphics = Graphics.FromImage(bmp)
        Dim Rect1 As New RectangleF(0, 0, aControl.Width, aControl.Height)

        Dim lineGBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color1, Color2, mode)
        g.FillRectangle(lineGBrush, Rect1)

        aControl.BackgroundImage = bmp
        g.Dispose()
    End Sub


    Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
        shimscustombuttonfunction(Button1, Color.LightGreen, Color.Green)
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
        Button1.BackgroundImage = Nothing
    End Sub
End Class

happy coding !!!!!