setToken($userToken,$userSecret); $args = array('status'=>$t); $oauth->fetch("$status_url",$args,"POST"); // WORKING $json = json_decode($oauth->getLastResponse(),true); $error = "SENT"; } catch(OAuthException $E) { // get error // message is protected $error = $E->getMessage(); } # output back to arduino echo ($command . " " . $t . " " . $error); # CHECK COMMAND } else if ($command == "TWEETSEARCH") { # SEARCH # search API URL $search_url = 'https://api.twitter.com/1.1/search/tweets.json'; try { # connect to api # https://dev.twitter.com/docs/api/1.1/get/search/tweets $oauth = new OAuth($conskey,$conssec,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI); # for search $oauth->setToken($userToken,$userSecret); $q = urlencode($var); // serach query $c = urlencode(1); // number of results $lang = urlencode("en"); // set language # build search query $args = array('q'=>$q, 'count'=>$c, 'lang'=>$lang, 'result_type'=>'recent'); # gets last tweet, arduino decides if it is new or not $oauth->fetch("$search_url",$args,"GET"); $json = json_decode($oauth->getLastResponse(),true); // print_r($json); // decode result foreach($json['statuses'] as $tweet) { $id = $tweet['id']; $text = $tweet['text']; # send data lables so arduino can reconise data # becasue arduino receives an HTTP headder i.e HTTP 200 OK echo ("tid=" . $id . "," . $text); } } catch(OAuthException $E) { $error = $E->getMessage(); } # COMMAND NOT FOUND } else { echo ("INVALID COMMAND"); exit(); } ?>