Components and supplies
Arduino Yun
Apps and platforms
Arduino IDE
Project description
Code
Code snippet #1
arduino
1/* 2 UpdateFacebookStatus 3 4 Demonstrates sending a Facebook status update using the Temboo Arduino Yun SDK. 5 6 This example code is in the public domain. 7*/ 8 9#include <Bridge.h> 10#include <Temboo.h> 11#include "TembooAccount.h" // contains Temboo account information 12 13/*** SUBSTITUTE YOUR VALUES BELOW: ***/ 14 15// Note that for additional security and reusability, you could 16// use a #define statement to specify this value in a .h file. 17 18// the Facebook Access Token, which can be obtained using the Temboo OAuth Wizard or Choreos 19const String FACEBOOK_ACCESS_TOKEN = "xxxxxxxxxx"; 20 21int numRuns = 1; // execution count, so this sketch doesn't run forever 22int maxRuns = 1; // the max number of times the Facebook SetStatus Choreo should run 23 24void setup() { 25 Serial.begin(9600); 26 27 // For debugging, wait until a serial console is connected. 28 delay(4000); 29 while(!Serial); 30 Bridge.begin(); 31} 32 33void loop() { 34 // while we haven't reached the max number of runs... 35 if (numRuns <= maxRuns) { 36 37 // print status 38 Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "..."); 39 40 // Define the status message we want to post on Facebook; since Facebook 41 // doesn't allow duplicate status messages, we'll include a changing value. 42 String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!"; 43 44 // define the Process that will be used to call the "temboo" client 45 TembooChoreo SetStatusChoreo; 46 47 // invoke the Temboo client 48 // NOTE that the client must be reinvoked and repopulated with 49 // appropriate arguments each time its run() method is called. 50 SetStatusChoreo.begin(); 51 52 // set Temboo account credentials 53 SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT); 54 SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); 55 SetStatusChoreo.setAppKey(TEMBOO_APP_KEY); 56 57 // tell the Temboo client which Choreo to run (Facebook > Publishing > SetStatus) 58 SetStatusChoreo.setChoreo("/Library/Facebook/Publishing/SetStatus"); 59 60 // set the required choreo inputs 61 // see https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/ 62 // for complete details about the inputs for this Choreo 63 64 SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN); 65 SetStatusChoreo.addInput("Message", statusMsg); 66 67 68 // tell the Process to run and wait for the results. The 69 // return code (returnCode) will tell us whether the Temboo client 70 // was able to send our request to the Temboo servers 71 unsigned int returnCode = SetStatusChoreo.run(); 72 73 // print the response code and API response. 74 Serial.println("Response code: " + String(returnCode)); 75 76 // note that in this case, we're just printing the raw response from Facebook. 77 // see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino 78 // for information on how to filter this data 79 while(SetStatusChoreo.available()) { 80 char c = SetStatusChoreo.read(); 81 Serial.print(c); 82 } 83 84 SetStatusChoreo.close(); 85 } 86 87 Serial.println("Waiting..."); 88 Serial.println(""); 89 90 delay(30000); // wait 30 seconds between SetStatus calls 91}
Comments
Only logged in users can leave comments
Arduino_Scuola
0 Followers
•0 Projects
Table of contents
Intro
0
0