Update Your Facebook Status with Temboo

Update Your Facebook Status with Temboo © GPL3+

We'll show you how you can post a Facebook status update from your Arduino Yún.

  • 591 views
  • 1 comment
  • 0 respects

Components and supplies

Apps and online services

About this project

Get Set Up

  • Make sure you have a Temboo account. If you don't already have one, you can register for a free account here.
  • With your Facebook application in place, visit the Facebook > Publishing > SetStatus Choreo we're using in this example, and use our OAuth Wizard to obtain a Facebook access token. This video demonstrates how to use our OAuth Wizards. You'll need this token when you create the Arduino sketch later in this example.
  • Make sure that your Yún is connected to the Internet.

Write the Sketch

Copy the sketch code below into a new tab in your Arduino IDE. This code calls the SetStatus Choreo, and you will need to replace the placeholder value in the code with your own Facebook access token value obtained in step 3 above.

/*
  UpdateFacebookStatus
  Demonstrates sending a Facebook status update using the Temboo Arduino Yun SDK.  
  This example code is in the public domain. 
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use a #define statement to specify this value in a .h file.
// the Facebook Access Token, which can be obtained using the Temboo OAuth Wizard or Choreos
const String FACEBOOK_ACCESS_TOKEN = "xxxxxxxxxx";
int numRuns = 1;   // execution count, so this sketch doesn't run forever
int maxRuns = 1;  // the max number of times the Facebook SetStatus Choreo should run
void setup() {
  Serial.begin(9600);
  
  // For debugging, wait until a serial console is connected.
  delay(4000);
  while(!Serial);
  Bridge.begin();
}
void loop() {
  // while we haven't reached the max number of runs...
  if (numRuns <= maxRuns) {
    // print status
    Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "...");
    
    // Define the status message we want to post on Facebook; since Facebook
    // doesn't allow duplicate status messages, we'll include a changing value.
    String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!";
    // define the Process that will be used to call the "temboo" client                
    TembooChoreo SetStatusChoreo;
    // invoke the Temboo client
    // NOTE that the client must be reinvoked and repopulated with
    // appropriate arguments each time its run() method is called.
    SetStatusChoreo.begin();
    
    // set Temboo account credentials
    SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT);
    SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    SetStatusChoreo.setAppKey(TEMBOO_APP_KEY);
    // tell the Temboo client which Choreo to run (Facebook > Publishing > SetStatus)
    SetStatusChoreo.setChoreo("/Library/Facebook/Publishing/SetStatus");
    // set the required choreo inputs
    // see  https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/
    // for complete details about the inputs for this Choreo
    
    SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN);    
    SetStatusChoreo.addInput("Message", statusMsg);
    // tell the Process to run and wait for the results. The 
    // return code (returnCode) will tell us whether the Temboo client 
    // was able to send our request to the Temboo servers
    unsigned int returnCode = SetStatusChoreo.run();
    
    // print the response code and API response.
    Serial.println("Response code: " + String(returnCode));
    // note that in this case, we're just printing the raw response from Facebook.
    // see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino
    // for information on how to filter this data    
    while(SetStatusChoreo.available()) {
      char c = SetStatusChoreo.read();
      Serial.print(c);
    }
    SetStatusChoreo.close();
  }
  Serial.println("Waiting...");
  Serial.println("");
  delay(30000); // wait 30 seconds between SetStatus calls  
}

Create Your Header File

The sketch above references the TembooAccount.h header file, which contains your Temboo account information.

If you are currently logged in, you'll see your account details in the code snippet below (otherwise you'll see placeholder values). Copy the code snippet into a new tab in Arduino and call it TembooAccount.h.

With both files in place you are ready to upload the sketch and post to Facebook with your Yún. Now you've got another way to impress your friends.

Note: Facebook will prevent you from posting similar status messages multiple times, so be careful not to run this sketch repeatedly without changing the status message.

#define TEMBOO_ACCOUNT "accountName"  // your Temboo account name 
#define TEMBOO_APP_KEY_NAME "myFirstApp"  // your Temboo app key name
#define TEMBOO_APP_KEY  "abc123xxxxxxxxxxxxxx"  // your Temboo app key

What's Next?

Now that you've figured out how to post Facebook, why not check out the other 2000+ Choreos in our Library and start thinking about all the possibilities for your next Yún project.

Need Help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.

Code

Code snippet #1Arduino
/*
  UpdateFacebookStatus

  Demonstrates sending a Facebook status update using the Temboo Arduino Yun SDK.  

  This example code is in the public domain. 
*/

#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information

/*** SUBSTITUTE YOUR VALUES BELOW: ***/

// Note that for additional security and reusability, you could
// use a #define statement to specify this value in a .h file.

// the Facebook Access Token, which can be obtained using the Temboo OAuth Wizard or Choreos
const String FACEBOOK_ACCESS_TOKEN = "xxxxxxxxxx";

int numRuns = 1;   // execution count, so this sketch doesn't run forever
int maxRuns = 1;  // the max number of times the Facebook SetStatus Choreo should run

void setup() {
  Serial.begin(9600);
  
  // For debugging, wait until a serial console is connected.
  delay(4000);
  while(!Serial);
  Bridge.begin();
}

void loop() {
  // while we haven't reached the max number of runs...
  if (numRuns <= maxRuns) {

    // print status
    Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "...");
    
    // Define the status message we want to post on Facebook; since Facebook
    // doesn't allow duplicate status messages, we'll include a changing value.
    String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!";

    // define the Process that will be used to call the "temboo" client                
    TembooChoreo SetStatusChoreo;

    // invoke the Temboo client
    // NOTE that the client must be reinvoked and repopulated with
    // appropriate arguments each time its run() method is called.
    SetStatusChoreo.begin();
    
    // set Temboo account credentials
    SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT);
    SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    SetStatusChoreo.setAppKey(TEMBOO_APP_KEY);

    // tell the Temboo client which Choreo to run (Facebook > Publishing > SetStatus)
    SetStatusChoreo.setChoreo("/Library/Facebook/Publishing/SetStatus");

    // set the required choreo inputs
    // see  https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/
    // for complete details about the inputs for this Choreo
    
    SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN);    
    SetStatusChoreo.addInput("Message", statusMsg);


    // tell the Process to run and wait for the results. The 
    // return code (returnCode) will tell us whether the Temboo client 
    // was able to send our request to the Temboo servers
    unsigned int returnCode = SetStatusChoreo.run();
    
    // print the response code and API response.
    Serial.println("Response code: " + String(returnCode));

    // note that in this case, we're just printing the raw response from Facebook.
    // see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino
    // for information on how to filter this data    
    while(SetStatusChoreo.available()) {
      char c = SetStatusChoreo.read();
      Serial.print(c);
    }

    SetStatusChoreo.close();
  }

  Serial.println("Waiting...");
  Serial.println("");

  delay(30000); // wait 30 seconds between SetStatus calls  
}

Comments

Similar projects you might like

Read And Update Databases With Temboo

Project tutorial by Temboo_OFFICIAL

  • 2,411 views
  • 2 comments
  • 5 respects

Simple, Robust M2M Messaging Via Amazon with Temboo

by Temboo_OFFICIAL

  • 487 views
  • 0 comments
  • 0 respects

Send an SMS using Twilio with Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,477 views
  • 1 comment
  • 1 respect

Send An Email From Your Gmail Account With Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,386 views
  • 0 comments
  • 2 respects

Post Data to a Google Spreadsheet with Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,223 views
  • 0 comments
  • 7 respects

Upload a File to your Dropbox Account with Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,191 views
  • 0 comments
  • 1 respect
Add projectSign up / Login