This script will send a tweet with Trigger Device @ Level - Time Stamp
using System;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.IO;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;
public class TweetHA : ScriptBase, ScriptInterface {
public void runScript() {
try {
//**** Variables ********//
// goto https://apps.twitter.com/
// Create a new app
// Provide a Name (Must be Unique to Twitter) a Description and use http://www.google.com for the website
// Accept the agreement
// go to the Keys and Access Tokens tab and copy the Consumer Key and Consumer Secret below
string ck = "
string cs = "
//
// click the button to create your access tokens and copy the token and secret below
string tk = "
string ts = "
//
// go to the permissions tab and change it to Read,Write and Access Direct Messages
// Will tweet the triggering device name @ Level - Time Stamp
//**** Variables ********//
// No Changes below
var deviceName = triggerMetaData.triggeringDevice.deviceName;
var deviceLevel = triggerMetaData.triggeringDevice.level;
string ht = "#TweetHA";
var msg = deviceName +" @ "+ deviceLevel +" - "+ DateTime.Now.ToShortTimeString()+ " " + ht;
string postBody = "status=" + Uri.EscapeDataString(msg);
string oauthconsumerkey = ck;
string oauthconsumerSecret = cs;
string oauthsignaturemethod = "HMAC-SHA1";
string oauthversion = "1.0";
string oauthtoken = tk;
string oauthtokensecret = ts;
string oauthnonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
string oauthtimestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString();
SortedDictionary
basestringParameters.Add("status", Uri.EscapeDataString(msg));
basestringParameters.Add("oauth
basestringParameters.Add("oauthconsumerkey", oauthconsumerkey);
basestringParameters.Add("oauthnonce", oauthnonce);
basestringParameters.Add("oauthsignaturemethod", oauthsignaturemethod);
basestringParameters.Add("oauthtimestamp", oauthtimestamp);
basestringParameters.Add("oauthtoken", oauthtoken);
string baseString = String.Empty;
baseString += "POST" + "&";
baseString += Uri.EscapeDataString("https://api.twitter.com/1.1/statuses/update.json") + "&";
foreach (KeyValuePair
{
baseString += Uri.EscapeDataString(entry.Key + "=" + entry.Value + "&");
}
baseString = baseString.Substring(0, baseString.Length - 3);
string signingKey = Uri.EscapeDataString(oauth
"&" + Uri.EscapeDataString(oauthtokensecret);
HMACSHA1 hasher = new HMACSHA1(new ASCIIEncoding()
Tweet Script
- 310 Views
- Last Post 20 November 2014
hdrider465@gmail.com
posted this
20 November 2014