Posting images to facebook?

Has anybody done any work with posting images to Facebook from openframeworks? There doesn’t seem to be a really good api out there that I can find.

If anybody else wants to be able to do this:

Setup your application in Facebook. Make sure you read the docs and set permissions as needed. I used the graph api. The photo kiosk I’m working on requires offline access, which is an option set in the app authorization stage. Then you’ll need curlpp and the code posted here:…-21#p234221

Feel free to email me if you need help with this.

Hi Jaypozo

the facebook forums no longer exist. Can you tell me how you managed to post to a users facebook wall. More importantly, the authentication side of things


hi jaypozo, hi az_rr

Did you post photo to FB without any offscreen browser?

I have searched graph api but could not find the direct way to get access_token from within third party app…

So I did it with ofxBerkelium and curl like this

  1. open Berkelium browser inside the oF app
  2. Redirect the user to FB login page using the URL below:
  3. Server returns authorization code
  4. Request access_token from Facebook using the URL below:
  5. Server returns access_token
  6. post image and access_token to "" using curl

This flow works, but sooooo tricky.
Is there any simple approach…?



You wouldn’t be able to share some of your code would you Akira?

Im having a bit of trouble

Hello Aaron,

OK. But I think my code is not the best approach
There should be more simple one.
Since the project is huge, I extract the essence of the code.
So this is kind of pseudo code.

The process has 2 big steps.

  1. get access token.
  2. post something to the FB

(I tried these steps without Berkelium (only curl), but curl does not work on step 1…
It should work, but did not. I am not sure why.)

  • open Berkelium browser
const string AUTH_CODE_TARGET_URL = "[";](";)  
const string AUTH_CODE_REDIRECT_URL = "&redirect_uri=[";](";)  
const string AUTH_CODE_PERMISSION_SCOPE = "&scope=publish_stream";  
void openBrowser()  
	browser->getWindow()->navigateTo(, url.length());  

  • user input userID and password.

  • on Berkelium’s callback function,
    ---- get authCode.
    ---- request “access token request url”
    ---- get “access token request url”
    ---- request ACCESSTOKEN

const string ACCESS_TOKEN_TARGET_URL = "[";](";)  
const string ACCESS_TOKEN_REDIRECT_URL = "&redirect_uri=[";](";)  
const string AUTH_CODE_PREFIX = "&code=";  
const string AUTH_CODE_RETURNING_GARBAGE = "[";](";)  
const string ACCESS_TOKEN_RETURNING_GARBAGE = "[";](";)  
void onAddressBarChanged(string newURL)   
	// get authorization code. Then request "access token request url".   
	if (ofIsStringInString(newURL, AUTH_CODE_RETURNING_GARBAGE))   
		authCode = newURL;  
		authCode.erase(0, AUTH_CODE_RETURNING_GARBAGE.length());  
						  AUTH_CODE_PREFIX + authCode;  
		browser->getWindow()->navigateTo(, tokenURL.length());  
		bDrawBrowser = false;  
	// get the "access token request url". Then request access token to that url with curl.  
	if (ofIsStringInString(newURL, ACCESS_TOKEN_RETURNING_GARBAGE) && !bDoneAccessTokenRequest)   
		accessTokenURL = newURL;  
		bDoneAccessTokenRequest = true;  
		accessTokenURL.replace(accessTokenURL.length()-2, accessTokenURL.length(), "");  
		CURL* easy_handle;  
		CURLcode result;  
		easy_handle = curl_easy_init();  
		curl_easy_setopt(easy_handle, CURLOPT_URL, accessTokenURL.c_str());  
		curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, curlWriter);  
		curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, &ACCESSTOKEN);  
		string prefix = "access_token=";		  
		string delim = "&";		  
		string expire = "expires";  
		ACCESSTOKEN.erase(0, prefix.length());  
		vector<string> split = ofSplitString(ACCESSTOKEN, delim);  
		for (int i = 0; i < split.size(); i++)   
			if (!ofIsStringInString(split[i], expire))   
				ACCESSTOKEN = split[i];  

  1. post image to FB with ACCESSTOKEN
void faceBookPost()   
	string path = PATH_TO_YOUR_IMAGE;  
	struct curl_httppost *post=NULL;  
	struct curl_httppost *last=NULL;  
	struct curl_slist *headers=NULL;  
	CURL * easyhandle;  
	easyhandle = curl_easy_init();  
	curl_easy_setopt(easyhandle, CURLOPT_VERBOSE, 1); // do this to make debugging easier  
	headers = curl_slist_append(headers, "Content-Type: multipart/form-data");  
	curl_formadd(&post, &last,  
				 CURLFORM_COPYNAME, "access_token",  
	curl_formadd(&post, &last,  
				 CURLFORM_COPYNAME, "file",  
				 CURLFORM_FILE, path.c_str(), CURLFORM_CONTENTTYPE, "image/jpg", CURLFORM_END);  
	curl_formadd(&post, &last,  
				 CURLFORM_COPYNAME, "message",  
	curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, "");  
	curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDSIZE, 23L);  
	curl_easy_setopt(easyhandle, CURLOPT_URL, "["]("));  
	/* Set the form info */  
	curl_easy_setopt(easyhandle, CURLOPT_HTTPPOST, post);  
	/* post away! */  
	/* free the post data again */  

Hope this help!


A lazy way to post images to facebook from an OF app is to use facebook’s ‘upload by email’ secret address (check your facebook settings to find it). You don’t need tokens or any authentication, you just need to know how to send emails from OF or call a script to send the email. I use this method all the time… and im lazy.


Im looking for a way to post images to facebook from an of app on osx. I see that are several addons to do that for iOS but i dont found nothing to do on desktop.

Also i read about the social.framework on osx but dont find any implementation on oF

Any clue with be wellcome :slight_smile: