Posting images on twitter with openframeworks

i would post images on my twitter account trough a OF addon. i found different addons




but i discovered that you can only search or post text tweet not to upload images. In alternatives i could upload images via flickr and then attach the string links in the tweet. Anyone has a suggestion or example on how achieve this?

i think that twurl https://github.com/marcel/twurl could be a solution, its easy to use see here the instructions, https://dev.twitter.com/docs/uploading-media and here https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media

Hi kalwalt,

I started working in a new fork of ofxTwitter last month cause I needed to make a project and with the new Twitter API 1.1 the old add-ons stopped working and I thought it will be nice to have a twitter OF add-on with all the API functions integrated.

I didn´t know about ofxTwitcurl. I´m using ofxOauth and ofxJSON for parsing. As ofxOAuth has not yet implanted POST method and I only needed to search tweets I stopped there. You can see my progress here but it´s really a work in progress.

Thanke you @pelayo, i discovered that ofxTwitcurl as is based on twitcurl can’t send images because sending media is not implemented in twitcurl… https://code.google.com/p/twitcurl/issues/detail?id=42

but found this library that implement upload images example-LibTwitter-Core , i think i will go to try this in OF and mybe in a Future to develop a little addon…

twurl is the way to go for me. Sending commands with a string by system(string) is easy. Look at an example:

//before you need to authenticate...
    string cmd = "twurl -X POST '/1.1/statuses/update_with_media.json' --file '" + ofToDataPath("test.jpg") +"' --file-field 'media[]' -d 'status=Hello oF! "+words[step] +"'" ;   // create the command
                cout << cmd << endl;
                system(cmd.c_str());

Hi @kalwalt,

That’s great and really straightfoward too. I’ve been working on ofxAuth a bit on my side implementing post and multipart/data form posts. Now I have a version of ofxTwitter that uploads photos to twitter via curl through my fork of ofxOAuth.

I have now a branch ‘feature-postmultipart’ on my ofxOauth fork that works but needs small fixes. I will try to ask balercpp later to revise and pull this changes into ofxOauth.

You can take a look in my github to the curl part.

Wow, thats great news @pelayo ! i see in your code the new changes, but how to post data with it? with this function: https://github.com/pelayomendez/ofxOAuth/blob/feature-postmultipart/formdata/src/ofxOAuth.cpp#L965 ? can you also a simple twitter example in your repo ?

@pelayo @bakercp i’m testing your multipart branch but i have an issue:

…/libs/libcurl/include/curl/curlrules.h|143|error: size of array ‘curl_rule_01’ is negative|

i’m working with OF 008 and linux64.

i realized that ofxOAuth addon seems tested only on OSX, there aren’t lib for windows or linux so i’m going to build the static libs for liboauth and libcurl… i will fork also the repo so we can upload the changes.

Hey all, if you’ve tested and confirmed it works, I’m happy to pull it in. You should be able to use liboauth via apt-get and a good addons_config.mk file. keep me posted and I’ll help!

@bakercp right now i’m testing your linux64 branch, it compile fine, when i run it, the twitter page to authenticate will open but when i authorize it and suddenly when it redirect to http://127.0.0.1:8080/?oauth_token=… the app crash and no xml file is saved. Maybe i miss some settings, you mention to set as web based app but i can’t find where is this setting in my twitter web page app settings.

Hey there, I’m hoping to look at this soon – but I’m a bit backlogged at the moment … the linux64 branch may be a bit out of date … I can’t recall. More soon.

thanks you for the answer @bakercp, i would use it for my thesis project, but if it’s not possible, i continue to use twurl as discussed in the previous posts.

Sorry for the delay about this. I have just now updated my fork of ofxOauth and ofxTwitter.

@kalwalt If you can see the authorization window I think your app configuration is fine.

@bakercp I have updated my pull request in ofxOAuth to include also the multipart form data functions needed to send photos from ofxTwitter.

I can only test in OSX so it would be great to get support for linux.

Hey this is great – @pelayo would you be willing to either update the existing twitter example or add an example that demonstrates this post behavior? Then we’ll be able to test it quickly … sorry, I would do it, but I’m slammed with deadlines these days. As soon as we get it tested and working on OSX, I’ll pull it in and we can get it integrated.

Thanks for your great work on this @kalwalt and @pelayo!

CB

Hi @bakercp Thanks. I have a working example via the new version of ofxTwitter I´m creating that works with API 1.1 https://github.com/pelayomendez/ofxTwitter/tree/master/example-post

this is super fine @pelayo! i will try this with the modified linux64 version of ofOauth, will see what happens. @bakercp i have done nothing! instead thanks for your interest.

@pelayo @bakercp i’m testing it but i have an issue with ofxJSON it seems that there was already a JSON issue on linux

@pelayo @bakercp the json issue was solved but i have another with ofxTwitter with varables initialized in the declarations:

running command: make -f Makefile Release
Compiling OF library for Release
make[2]: Nessuna operazione da eseguire per “ReleaseABI”.
Done!
Compiling example_post for Release
Compiling src/main.cpp
g++ -c -Os -Wall -march=native -mtune=native -DOF_USING_GTK -DOF_USING_MPG123 -I/usr/include/jsoncpp -fpermissive -I./src -I…/…/…/addons/ofxXmlSettings/src -I…/…/…/addons/ofxXmlSettings/libs -I…/…/…/addons/ofxJSON/src -I…/…/…/addons/ofxJSON/libs -I…/…/…/addons/ofxOAuth/src -I…/…/…/addons/ofxOAuth/libs -I…/…/…/addons/ofxOAuth/libs/liboauth -I…/…/…/addons/ofxOAuth/libs/liboauth/lib -I…/…/…/addons/ofxOAuth/libs/liboauth/lib/linux64 -I…/…/…/addons/ofxOAuth/libs/liboauth/lib/osx -I…/…/…/addons/ofxOAuth/libs/liboauth/include -I…/…/…/addons/ofxOAuth/libs/liboauth/include -I…/…/…/addons/ofxTwitter/src -pthread -D_REENTRANT -I/usr/local/include -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/gstreamer-0.10 -I/usr/include/libxml2 -I/usr/include/alsa -I/usr/include/libdrm -I/usr/include/GL -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I…/…/…/libs/fmodex/include -I…/…/…/libs/glfw/include -I…/…/…/libs/glfw/include/GLFW -I…/…/…/libs/kiss/include -I…/…/…/libs/openssl/include -I…/…/…/libs/openssl/include/openssl -I…/…/…/libs/poco/include -I…/…/…/libs/portaudio/include -I…/…/…/libs/rtAudio/include -I…/…/…/libs/tess2/include -I…/…/…/libs/openFrameworks -I…/…/…/libs/openFrameworks/app -I…/…/…/libs/openFrameworks/graphics -I…/…/…/libs/openFrameworks/3d -I…/…/…/libs/openFrameworks/sound -I…/…/…/libs/openFrameworks/math -I…/…/…/libs/openFrameworks/types -I…/…/…/libs/openFrameworks/communication -I…/…/…/libs/openFrameworks/utils -I…/…/…/libs/openFrameworks/gl -I…/…/…/libs/openFrameworks/video -I…/…/…/libs/openFrameworks/events -MMD -MP -MF obj/linux64/Release/src/main.d -MT obj/linux64/Release/src/main.o -o obj/linux64/Release/src/main.o -c src/main.cpp
In file included from …/…/…/addons/ofxOAuth/src/ofxOAuth.h:36:0,
from …/…/…/addons/ofxTwitter/src/ofxTwitter.h:29,
from src/testApp.h:4,
from src/main.cpp:2:
…/…/…/addons/ofxOAuth/src/ofxOAuthVerifierCallbackServer.h: In member function ‘bool ofxOAuthAuthReqHandler::parseQuery(const string&, Poco::Net::NameValueCollection&)’:
…/…/…/addons/ofxOAuth/src/ofxOAuthVerifierCallbackServer.h:259:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
In file included from …/…/…/addons/ofxTwitter/src/ofxTwitter.h:32:0,
from src/testApp.h:4,
from src/main.cpp:2:
…/…/…/addons/ofxTwitter/src/ofxTwitterTweet.h: At global scope:
…/…/…/addons/ofxTwitter/src/ofxTwitterTweet.h:37:37: warning: ISO C++ forbids initialization of member ‘profile_image_url_loaded’ [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterTweet.h:37:37: warning: making ‘profile_image_url_loaded’ static [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterTweet.h:37:37: error: ISO C++ forbids in-class initialization of non-const static member ‘profile_image_url_loaded’
…/…/…/addons/ofxTwitter/src/ofxTwitterTweet.h:41:38: warning: ISO C++ forbids initialization of member ‘profile_banner_url_loaded’ [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterTweet.h:41:38: warning: making ‘profile_banner_url_loaded’ static [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterTweet.h:41:38: error: ISO C++ forbids in-class initialization of non-const static member ‘profile_banner_url_loaded’
In file included from …/…/…/addons/ofxTwitter/src/ofxTwitter.h:33:0,
from src/testApp.h:4,
from src/main.cpp:2:
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:17:34: error: a call to a constructor cannot appear in a constant-expression
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:17:34: warning: ISO C++ forbids initialization of member ‘geocode’ [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:17:34: warning: making ‘geocode’ static [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:17:34: error: invalid in-class initialization of static data member of non-integral type ‘ofPoint {aka ofVec3f}’
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:19:22: warning: ISO C++ forbids initialization of member ‘bUseMiles’ [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:19:22: warning: making ‘bUseMiles’ static [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:19:22: error: ISO C++ forbids in-class initialization of non-const static member ‘bUseMiles’
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:20:26: warning: ISO C++ forbids initialization of member ‘geocode_radius’ [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:20:26: warning: making ‘geocode_radius’ static [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:20:26: error: ISO C++ forbids in-class initialization of non-const static member ‘geocode_radius’
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:27:17: warning: ISO C++ forbids initialization of member ‘count’ [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:27:17: warning: making ‘count’ static [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:27:17: error: ISO C++ forbids in-class initialization of non-const static member ‘count’
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:31:21: warning: ISO C++ forbids initialization of member ‘since_id’ [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:31:21: warning: making ‘since_id’ static [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:31:21: error: ISO C++ forbids in-class initialization of non-const static member ‘since_id’
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:32:19: warning: ISO C++ forbids initialization of member ‘max_id’ [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:32:19: warning: making ‘max_id’ static [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:32:19: error: ISO C++ forbids in-class initialization of non-const static member ‘max_id’
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:33:29: warning: ISO C++ forbids initialization of member ‘include_entities’ [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:33:29: warning: making ‘include_entities’ static [-fpermissive]
…/…/…/addons/ofxTwitter/src/ofxTwitterSearch.h:33:29: error: ISO C++ forbids in-class initialization of non-const static member ‘include_entities’
make[1]: *** [obj/linux64/Release/src/main.o] Errore 1
make: *** [Release] Errore 2
Process terminated with status 2 (0 minutes, 2 seconds)
10 errors, 19 warnings

this issue can be solved with some cflags or the code need to be changed?

i have a rearranged the code to solve the issue above but i get again the curl issue

…/…/ofxOAuth/libs/libcurl/include/curl/curlrules.h|143|error: size of array ‘curl_rule_01’ is negative|

even if i have your @bakercp version of addon_config.mk in ofxOAuth addon folder with the ADDON_LDFLAGS = -lcurl