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.
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.
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.
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.
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.
register an API with Instagram and get a client_id and client_secret
set up the call back url to redirect to your computer
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)
In the attached file fill in client_id and client_secret as well as callback_url in the tables feeding the various web DATs.
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
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
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)
You might have to adjust the parsing depending on the response message from Instagram
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
I saw that the streaming API for twitter could also work similar to this…
Very helpful while working on this was apigee.com/
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.
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.