Hardware Reference
In-Depth Information
if
(
error
) {
console
.
log
(
'Error: '
+
(
error
.
code
?
error
.
code
+
' '
+
error
.
message
:
error
.
message
));
}
if
(
result
) {
console
.
log
(
result
);
}
}
);
// node-twitter is made available under terms of the BSD 3-Clause
License.
// http://www.opensource.org/licenses/BSD-3-Clause
The code in
Example 6-12
sends a tweet whenever a button is pushed.
Example 6-12. Tweet when a button is pushed (twitterPushbutton.js)
#!/usr/bin/env node
// From: https://www.npmjs.org/package/node-twitter
// Tweets with attached image media (JPG, PNG or GIF) can be posted
// using the upload API endpoint.
var
Twitter
=
require
(
'node-twitter'
);
var
b
=
require
(
'bonescript'
);
var
key
=
require
(
'./twitterKeys'
);
var
gpio
=
"P9_42"
;
var
count
=
0
;
b
.
pinMode
(
gpio
,
b
.
INPUT
);
b
.
attachInterrupt
(
gpio
,
sendTweet
,
b
.
FALLING
);
var
twitterRestClient
=
new
Twitter
.
RestClient
(
key
.
API_KEY
,
key
.
API_SECRET
,
key
.
TOKEN
,
key
.
TOKEN_SECRET
);
function
sendTweet
() {
console
.
log
(
"Sending..."
);
count
++;
twitterRestClient
.
statusesUpdate
(
{
'status'
:
'Posting tweet '
+
count
+
' via my BeagleBone
Black'
, },
function
(
error
,
result
) {
if
(
error
) {