1 | /*
|
---|
2 | UpdateFacebookStatus
|
---|
3 |
|
---|
4 | Demonstrates sending a Facebook status update using Temboo from an Arduino Y炭n.
|
---|
5 |
|
---|
6 | Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
---|
7 |
|
---|
8 | A Temboo account and application key are necessary to run all Temboo examples.
|
---|
9 | If you don't already have one, you can register for a free Temboo account at
|
---|
10 | http://www.temboo.com
|
---|
11 |
|
---|
12 | In order to run this sketch, you'll need to register an application using
|
---|
13 | the Facebook dev console at https://developers.facebook.com/apps -- after creating
|
---|
14 | the app, log in to Temboo and visit https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/
|
---|
15 | to use our OAuth Wizard (or OAuth Choreos) to obtain a Facebook access token.
|
---|
16 | Substitute your access token for the placeholder value of FACEBOOK_ACCESS_TOKEN below.
|
---|
17 |
|
---|
18 | This example assumes basic familiarity with Arduino sketches, and that your Y炭n
|
---|
19 | is connected to the Internet.
|
---|
20 |
|
---|
21 | Want to use another social API with your Arduino Y炭n? We've got Twitter, Google+,
|
---|
22 | Instagram, Tumblr and more in our Library!
|
---|
23 |
|
---|
24 | This example code is in the public domain.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include <Bridge.h>
|
---|
28 | #include <Temboo.h>
|
---|
29 | #include "TembooAccount.h" // contains Temboo account information,
|
---|
30 | // as described in the footer comment below
|
---|
31 |
|
---|
32 | /*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
---|
33 |
|
---|
34 | // Note that for additional security and reusability, you could
|
---|
35 | // use a #define statement to specify this value in a .h file.
|
---|
36 |
|
---|
37 | // the Facebook Access Token, which can be obtained using the Temboo OAuth Wizard or Choreos
|
---|
38 | const String FACEBOOK_ACCESS_TOKEN = "xxxxxxxxxx";
|
---|
39 |
|
---|
40 |
|
---|
41 | int numRuns = 1; // execution count, so this sketch doesn't run forever
|
---|
42 | int maxRuns = 10; // the max number of times the Facebook SetStatus Choreo should run
|
---|
43 |
|
---|
44 | void setup() {
|
---|
45 | Serial.begin(9600);
|
---|
46 |
|
---|
47 | // For debugging, wait until a serial console is connected.
|
---|
48 | delay(4000);
|
---|
49 | while(!Serial);
|
---|
50 | Bridge.begin();
|
---|
51 | }
|
---|
52 |
|
---|
53 | void loop() {
|
---|
54 | // while we haven't reached the max number of runs...
|
---|
55 | if (numRuns <= maxRuns) {
|
---|
56 |
|
---|
57 | // print status
|
---|
58 | Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "...");
|
---|
59 |
|
---|
60 | // Define the status message we want to post on Facebook; since Facebook
|
---|
61 | // doesn't allow duplicate status messages, we'll include a changing value.
|
---|
62 | String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!";
|
---|
63 |
|
---|
64 | // define the Process that will be used to call the "temboo" client
|
---|
65 | TembooChoreo SetStatusChoreo;
|
---|
66 |
|
---|
67 | // invoke the Temboo client
|
---|
68 | // NOTE that the client must be reinvoked and repopulated with
|
---|
69 | // appropriate arguments each time its run() method is called.
|
---|
70 | SetStatusChoreo.begin();
|
---|
71 |
|
---|
72 | // set Temboo account credentials
|
---|
73 | SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT);
|
---|
74 | SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
---|
75 | SetStatusChoreo.setAppKey(TEMBOO_APP_KEY);
|
---|
76 |
|
---|
77 | // tell the Temboo client which Choreo to run (Facebook > Publishing > SetStatus)
|
---|
78 | SetStatusChoreo.setChoreo("/Library/Facebook/Publishing/SetStatus");
|
---|
79 |
|
---|
80 | // set the required choreo inputs
|
---|
81 | // see https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/
|
---|
82 | // for complete details about the inputs for this Choreo
|
---|
83 |
|
---|
84 | SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN);
|
---|
85 | SetStatusChoreo.addInput("Message", statusMsg);
|
---|
86 |
|
---|
87 |
|
---|
88 | // tell the Process to run and wait for the results. The
|
---|
89 | // return code (returnCode) will tell us whether the Temboo client
|
---|
90 | // was able to send our request to the Temboo servers
|
---|
91 | unsigned int returnCode = SetStatusChoreo.run();
|
---|
92 |
|
---|
93 | // print the response code and API response.
|
---|
94 | Serial.println("Response code: " + String(returnCode));
|
---|
95 |
|
---|
96 | // note that in this case, we're just printing the raw response from Facebook.
|
---|
97 | // see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino
|
---|
98 | // for information on how to filter this data
|
---|
99 | while(SetStatusChoreo.available()) {
|
---|
100 | char c = SetStatusChoreo.read();
|
---|
101 | Serial.print(c);
|
---|
102 | }
|
---|
103 |
|
---|
104 | SetStatusChoreo.close();
|
---|
105 | }
|
---|
106 |
|
---|
107 | Serial.println("Waiting...");
|
---|
108 | Serial.println("");
|
---|
109 |
|
---|
110 | delay(30000); // wait 30 seconds between SetStatus calls
|
---|
111 | }
|
---|
112 |
|
---|
113 | /*
|
---|
114 | IMPORTANT NOTE: TembooAccount.h:
|
---|
115 |
|
---|
116 | TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
|
---|
117 | You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
|
---|
118 | by inserting your own Temboo account name and app key information. The contents of the file should
|
---|
119 | look like:
|
---|
120 |
|
---|
121 | #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
---|
122 | #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
---|
123 | #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
---|
124 |
|
---|
125 | You can find your Temboo App Key information on the Temboo website,
|
---|
126 | under My Account > Application Keys
|
---|
127 |
|
---|
128 | The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
---|
129 |
|
---|
130 | Keeping your account information in a separate file means you can share the main .ino file without worrying
|
---|
131 | that you forgot to delete your credentials.
|
---|
132 | */
|
---|