Instagram SDK Wrapper

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User

Used SocialApi classes:
  • InstagramProvider: A non activity object that must be declared in any Sub Process_Globals.
  • SocialApiActivity: An activity object that can be only declared in a Sub Globals and is used to bind a InstagramProvider object to an activity through the InstagramProvider.SetActivity method.
Getting started
  1. Download the latest socialapi package, extract it anywhere on your hard disk and note the folder name.
  2. Copy the wrapper files (jar + xml) in the socialapi folder into your B4A Libraries folder.
  3. Each sample in the socialapi\instagram\samples folder has AdditionalRes and AdditionalJar directives that have to be changed. Change the C:\b4a-dev folder to where you have extracted the socialapi archive.

The samples archive contains:
  • Sample1: Quick start sample that can be used as a bare-bone template for your new apps
Step-by-step new app tutorial (based on Sample1)

1. Add following code to your manifest:

2. Add following directives to your project's main file:
#AdditionalRes: <your-installation-folder>\socialapi\instagram\sdk\res
#AdditionalJar: <your-installation-folder>\socialapi\instagram\sdk\instagramdk.jar

3. Select the SocialApi and InstagramProvider libraries from the list of the available libraries in the IDE. Declare a InstagramProvider and a SocialApiActivity object in Sub Process_Globals and Sub Globals respectively
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim Instagram As InstagramProvider
    Instagram.Initialize("<your-client-id>", "<your-client-secret> ", "<your-callback-url>")

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim ThisActivity As SocialApiActivity
End Sub

4. Call the InstagramProvider.SetActivity method in your Sub Activity_Resume in order to bind the InstagramProvider instance to the current activity passing the name of the event that will be raised every time the InstagramProvider session changes.
Sub Activity_Resume
End Sub

5. Create your events
Sub Instagram_Event (Provider as SocialApiProvider)
    BtnConnect.Enabled = Not(Provider.Connected)
    BtnDisconnect.Enabled = Provider.Connected
End Sub

Sub Twitter_Connected (Provider as SocialApiProvider)
    Msgbox(Provider.Me, "!")
End Sub

Sub Twitter_Disconnected (Provider as SocialApiProvider)
    Msgbox("Bye bye!", "JustDisconnected!")
End Sub

Sub Twitter_Failed (Provider as SocialApiProvider)
    If Msgbox2("Failed to actualize your details."&CRLF&CRLF&"Retry?", "Error", "Yes", "No", "", Null) = DialogResponse.POSITIVE Then
    End If
End Sub

6. Create the login/logout handlers. The login and logout actions are performed asynchronously
Sub BtnConnect_Click
End Sub

Sub BtnDisconnect_Click
End Sub

8. Do something and evaluate the result
Sub BtnRecentMedia_Click
    Dim Result As InstagramResult

    Result = Instagram.GetRecentMedia(1574083, 5) '1574083 = the id of "snoopdog", 0 = me
    If Result.Success Then
        Msgbox(Result.Map, "Snoop's recent media")
    End If
End Sub

Done! Now we have to setup our app in our Instagram developer dashboard.

Setup our app in Instagram developer dashboard

Follow the steps described here:

Done! You are ready to go! :D

Useful links

Please test and post any feedback, questions, comments you may have!
That's all for now folks!~

Version history until SocialApi 2.3

  • Restructured into a single package (socialapi) after finding out how to properly use the #AdditionalRes directive to avoid conflict with other b4a libraries
  • Initial version


  • sample1-1.jpg
    16.1 KB · Views: 433
  • sample1-2.jpg
    22.3 KB · Views: 336
Last edited:


Active Member
Licensed User
Longtime User
You are amazing man. Thanks for all of your effort, you just elevated the B4A to the higher level!

Periklis Koutsogiannis

Active Member
Licensed User
Longtime User


Well-Known Member
Licensed User
Longtime User
So if we need to post a photo we can't do it with Instagram SDK wrapper, right ?