Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

Instagram Real Time Python script

General discussion about anything TouchDesigner

Instagram Real Time Python script

Postby prochoy » Fri Jan 16, 2015 12:35 pm

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.

https://github.com/Instagram/python-instagram
http://instagram.com/developer/realtime/
http://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.

http://www.derivative.ca/Forum/viewtopi ... =22&t=8767
Last edited by prochoy on Wed Apr 13, 2016 3:32 pm, edited 1 time in total.
prochoy
 
Posts: 36
Joined: Wed Dec 31, 2014 2:20 pm

Re: Instagram Real Time Python script

Postby mgebste » Sat Apr 18, 2015 9:37 am

HI Buddy,

Did you have any luck with that?

best regards
mgebste
 
Posts: 67
Joined: Thu May 22, 2014 11:12 am

Re: Instagram Real Time Python script

Postby nettoyeur » Sat Apr 18, 2015 12:46 pm

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.
Idzard Kwadijk | freelance TouchDesigner consultant | LinkedIn
nettoyeur
 
Posts: 515
Joined: Mon Oct 15, 2012 12:00 pm
Location: Amsterdam, The Netherlands

Re: Instagram Real Time Python script

Postby elburz » Sun Apr 19, 2015 5:59 pm

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 Sorkhabi
Creative + Technology
nVoid Art-Tech Limited
http://nvoid.com
elburz
 
Posts: 1760
Joined: Fri Jun 01, 2012 6:55 pm
Location: Toronto, Canada

Re: Instagram Real Time Python script

Postby mgebste » Sun Apr 19, 2015 11:50 pm

Elburz,

Just sent you an email

best regards
mgebste
 
Posts: 67
Joined: Thu May 22, 2014 11:12 am

Re: Instagram Real Time Python script

Postby snaut » Mon Apr 20, 2015 12:04 am

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
Code: Select all
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
Code: Select all
peer.sendBytes(challenge)


Since then I'm impressed how many people use instagram :)
User avatar
snaut
Staff
 
Posts: 693
Joined: Mon Nov 12, 2007 6:21 pm
Location: Toronto

Re: Instagram Real Time Python script

Postby elburz » Mon Apr 20, 2015 12:49 am

Markus, did you get it working with Six? Six kept throwing errors for me, so I cut the cord on it!
--
Elburz Sorkhabi
Creative + Technology
nVoid Art-Tech Limited
http://nvoid.com
elburz
 
Posts: 1760
Joined: Fri Jun 01, 2012 6:55 pm
Location: Toronto, Canada

Re: Instagram Real Time Python script

Postby bLackburst » Mon Apr 20, 2015 3:44 am

Can you please post your script+toe Snaut?
bLackburst
 
Posts: 233
Joined: Thu Sep 01, 2011 3:56 am
Location: Melbourne, Australia

Re: Instagram Real Time Python script

Postby snaut » Mon Apr 20, 2015 11:16 am

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:
    Code: Select all
    GET /?hub.mode=subscribe&hub.challenge=15f7d1a91c1f40f8a748fd134752feb3
  7. 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:
    Code: Select all
    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)
  8. You might have to adjust the parsing depending on the response message from Instagram
  9. 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 http://apigee.com/

Hope it helps
Cheers
Markus
Attachments
instagram.toe
(8.89 KiB) Downloaded 478 times
User avatar
snaut
Staff
 
Posts: 693
Joined: Mon Nov 12, 2007 6:21 pm
Location: Toronto

Re: Instagram Real Time Python script

Postby bLackburst » Wed Apr 22, 2015 10:06 am

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.
bLackburst
 
Posts: 233
Joined: Thu Sep 01, 2011 3:56 am
Location: Melbourne, Australia

Next

Return to General TouchDesigner Discussion

Who is online

Users browsing this forum: ben and 5 guests