Instagram Real Time Python script

I am attempting to write a python script that subscribes to a specific Instagram tag and pipes out any new images in real time into a DAT table that I can queue up and display.

I have done similar things with the Twitter API generating an OAuth URL and feeding into a JSON structure and grabbing data from that. However, I seem to be having trouble with the python part in Touch Designer. I have gone through the documentation below but am unsure if I need to install the Instagram python library for TD to read it or how to call it.

github.com/Instagram/python-instagram
instagram.com/developer/realtime/
instagram.com/developer/authentication/

Any tips on how to get this setup in TD would be very helpful.

Cheers!

UPDATE
After coming back to this I skipped using the ‘python-instagram’ library and created a .tox for the new Instagram authentication process using the ‘Requests’ or standard library. Below is a link to the .tox I posted on the shared components page.

derivative.ca/Forum/viewtopi … =22&t=8767

HI Buddy,

Did you have any luck with that?

best regards

According to the github page of your chosen library,
you need to install the python-instagram module.
It requires the modules httplib2, simplejson and six to be installed as well.

read the wiki on how to install python modules for use in TD.

We got it working on our end, you can get httplib2 and simplejson pretty easy.

Six is a bit of pain, but if you go into the python-instagram source code, you can manually swap out all the calls to Six and replace them with what they need to be. Six basically is used to make libraries that work with Python 2 and 3 by redirecting import calls and such. So if you just google what the modules you need are in 3 you can sub those in for the calls to Six.

Elburz,

Just sent you an email

best regards

I did a little experiment and got it all working with some help of the tcpip dat and using duckdns to reroute a url to my computer.

But the basics are, after subscribing via

https://api.instagram.com/v1/subscriptions/

the tcp/ip callback had to responde with the challenge object send by instagram.
so I parsed out the challenge, appended a newline and did a

peer.sendBytes(challenge)

Since then I’m impressed how many people use instagram :slight_smile:

Markus, did you get it working with Six? Six kept throwing errors for me, so I cut the cord on it!

Can you please post your script+toe Snaut?

Hey,

attached is the project file. It’s an experiment so there needs to be a bit more work to make it function for everyone equaly but I’ll explain what I did.

For what I’m trying to do with it I don’t need OAuth as i don’t need access to a particular user information. Most of Instagrams API also works with the client_id and client_secret.

  1. register an API with Instagram and get a client_id and client_secret
  2. set up the call back url to redirect to your computer
  3. I used duckdns.org, had to setup a router mapping to pass any requests to my computer and also ran into this old problem where Skype uses port 80 (port 80 being the default web port - but you can change that in Skypes advanced settings)
  4. In the attached file fill in client_id and client_secret as well as callback_url in the tables feeding the various web DATs.
  5. Now in the subscribe Web DAT, hit Submit. This will get Instagram to send a response to your specified callback_url and therefor the response ends up in the tcpip DAT
  6. Here I didn’t do too much work, the tcpip DAT will parse the incoming text for Instagrams response. In their API doc they say to expect a message like this:
GET /?hub.mode=subscribe&hub.challenge=15f7d1a91c1f40f8a748fd134752feb3
  1. now we need to send back the challenge so in the tcpip callback you can see how i parse out the challenge and send it back:

if message.startswith('GET /?hub.challenge'): #must reply with challeng challenge = message[20:52]+'\n' print(challenge) peer.sendBytes(challenge) op('closeConnection').run(peer,delayFrames=10)

  1. You might have to adjust the parsing depending on the response message from Instagram
  2. From this point on, Instagram is sending you a little json dictionary everytime a new post is made for your subscription. In the tcpip callbacks I’m just triggering the fetch parameter on the getRecentByTag webDat

Here is were it needs a bit of work:

  • Parse out the Header information correctly
  • Parse out the json dictionary correctly for the subscription updates so you can deal with multiple subscriptions

But the basics are in this and no external modules need to be installed :slight_smile:
I saw that the streaming API for twitter could also work similar to this…
Very helpful while working on this was apigee.com/

Hope it helps
Cheers
Markus
instagram.toe (8.89 KB)

Thanks for that. I’ll try to get my head around it tomorrow when I’m feeling productive/masochistic. Then figure out the best way to save the images so it doesn’t slow the system down.

O wow, Twitter too? That would be amazing. Components like these would be very useful to those of us without brains the size of a planet.

How would we get around the callback url if we were using a venue internet connection and arbitrary touch machine?
Ideally it would be portable, as in plug in touch dongle into random machine, open the project file and it will work if there’s an internet connection. I just know that oftentimes we won’t have access to port forwarding etc.

Yeah - this is definitely a limiting factor.
I guess you would have to build a little webapp and connect to it via Websockets…

cheers
Markus