Creating a Basic Instagram App with Visual Basic

Instagram is a nifty little app that allows you to share photos on social media. There is one caveat with Instagram, though; it is available solely on a mobile platform. Today, I will show you how to create a little Instagram app with Visual Basic.

Getting Started

As stated throughout my social media article series this month, you cannot directly start coding. To write an app that makes use of Instagram’s API, you first need to create a developer’s account with them. Naturally, I had to first download Instagram on my Android device. By downloading Instagram, you needed to supply an email address. This address is crucial when you want to create a developer’s account.

Once you have Instagram installed, you can navigate to this link and create a developer’s account. You need to supply information such as your details, the app’s name, and the app’s intended purpose. Once you have supplied this information, Instagram will provide you with a developer key and secret, as shown in Figure 1.

Instagram1
Figure 1: Instagram developer details

Instagram Libraries

There are a few Instagram SDKs and wrappers floating around. Here is a short list of the most popular ones:

Our Project

Today’s little project will show you how to make use of the Instasharp wrapper for Instagram and how to read certain feeds. Nothing too overly complicated.

Design

Create a new Windows Store project with VB and add two listboxes to your page. Name these anything you like. If you haven’t downloaded the Instasharp wrapper yet, I suggest you do so now before continuing. After you have downloaded the wrapper, add a reference to it by clicking Project, Add reference, Navigate to the libraries location and selected it, as shown in Figure 2.

Instagram2
Figure 2: Instasharp Reference

Code

Not much code, honestly, because this is just an example to get you started on your way.

Add the namespaces:

Imports InstaSharp
Imports NewtonSoft.JSon

These two namespaces give you access to all of Instasharp’s and JSON’s abilities. JSON stands for JavaScript Object Notation. For a full explanation and understanding of JSON, feel free to have a read through these articles:

Add the modular variables:

Dim config = New InstaSharp.InstagramConfig("https://api.instagram.com/v1",
   "https://api.instagram.com/oauth", "693103ec45c44c40be1690f675765def",
   "c832ed3dd0a048ec87ec68c712d14237", "http://localhost:80")

Dim oauth = New OAuth(config)
Dim link = oauth.AuthLink(config, scopes, oauth.ResponseType.Code)

Dim authInfo = Await oauth.RequestToken("693103ec45c44c40be1690f675765def")
Dim tagsApi = New InstaSharp.Endpoints.Tags(config, authInfo)
Dim tagInfo = tagsApi.Get("tagName")

The first object, config, allows you to get access to Instagram’s functionalities, because of the way the Instasharp DLL works. You have to supply the location of the Instagram API, where to get the Authorizing information, your app’s key, and your app’s secret. Secondly, you instantiate the OAuth object. The rest of the objects just ensure that you may use the Instagram API in your application.

Add the last piece of the puzzle:

Public Sub GetFeed()
   Dim userlist1 = New List(Of InstaSharp.Models.User)
   Dim userlist2 = New List(Of InstaSharp.Models.User)
   Dim Media = New List(Of InstaSharp.Models.Media)

   Dim users As InstaSharp.Endpoints.Users(config)
   Dim result = users.Feed("self")
   userlist1 = result.Result.Data

   lstList1.Items.Add(userlist1)

   Dim result2 = users.Search("beyonce")
   userlist2 = result.Result.Data
   lstList2.Items.Add(userlist2)

End Sub
Private Sub MainPage_Loaded(sender As Object, _
   e As RoutedEventArgs) Handles Me.Loaded


   GetFeed()

End Sub

This sub creates two generic lists. The first list contains my feed, whereas the second list shows the feed from “beyonce” inside listboxes.

Hannes DuPreez
Hannes DuPreez
Ockert J. du Preez is a passionate coder and always willing to learn. He has written hundreds of developer articles over the years detailing his programming quests and adventures. He has written the following books: Visual Studio 2019 In-Depth (BpB Publications) JavaScript for Gurus (BpB Publications) He was the Technical Editor for Professional C++, 5th Edition (Wiley) He was a Microsoft Most Valuable Professional for .NET (2008–2017).

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read