rke211 Posted May 11, 2012 Share Posted May 11, 2012 So i have added a custom field for twitter usernames for my clients Ive then made a hook that posts on their twitter telling them they have a support reply this is simple enough but im just wondering if their was an easier way than searching the db to get the custom fields etc. require_once($_SERVER['DOCUMENT_ROOT'].'/twitter/twitteroauth.php'); function reply_twitter($vars) { $consumerKey = '******'; $consumerSecret = '******'; $OAuthToken = '******'; $OAuthSecret = '******'; $ticketid = $vars['ticketid']; $ticket = mysql_query("SELECT * FROM `tbltickets` WHERE `tid` ='".$vars['ticketid']."'"); if(mysql_num_rows($ticket)){ $t = mysql_fetch_array($ticket); if($t['userid'] > 0){ $user = mysql_query("SELECT * FROM `tblcustomfieldsvalues` WHERE `fieldid` = '6' AND `relid` = '".$t['userid']."'"); if(mysql_num_rows($user)){ $u = mysql_fetch_array($user); if($u['value'] != NULL || $u['value'] != ""){ $tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret); $message = "@".$u['value']." You have a new support ticket response from @DuckHost"; $tweet->post('statuses/update', array('status' => "$message")); } // end value check } // end user rows } // end userid check } // end ticket rows } // end function add_hook("TicketAdminReply",1,"reply_twitter"); 0 Quote Link to comment Share on other sites More sharing options...
altomarketing Posted May 11, 2012 Share Posted May 11, 2012 great job, how to get twitter Consumer and secret key? 0 Quote Link to comment Share on other sites More sharing options...
rke211 Posted May 11, 2012 Author Share Posted May 11, 2012 https://dev.twitter.com/ login through your account and setup an application as read and write i cant emphasis that enough i spent 20 minutes with the right code not realising i simply had the wrong setting on twitter lol But thanks i figured i know a few people who use twitter a lot more than they check their emails so why not take advantage of that fact ive had to recode my twitter feed though so it doesnt post on our homepage "@blah You have a new support ticket response from @DuckHost" was easy enough but just worth baring in mind 0 Quote Link to comment Share on other sites More sharing options...
rke211 Posted May 12, 2012 Author Share Posted May 12, 2012 Apologises for the double post but a kinda crucial thing i just realised Twitter dont allow double posting so it wont let you post for instance @client you have a new support ticket response @twitter then post another one @client you have a new support ticket response @twitter which means we need a work around now at first i thought yeh just stick the ticket id in and that fixed it for one instance atleast so after that the only other option to make it unique is to stick the time in it or something similar i suppose there is always the option of some really long if statement that has a lot of different ways of saying the same thing but i just stuck the time in so here is the new one require_once($_SERVER['DOCUMENT_ROOT'].'/twitter/twitteroauth.php'); function reply_twitter($vars) { $consumerKey = '****'; $consumerSecret = '****'; $OAuthToken = '****'; $OAuthSecret = '****'; $ticketid = $vars['ticketid']; $ticket = mysql_query("SELECT * FROM `tbltickets` WHERE `id` ='".$vars['ticketid']."'"); if(mysql_num_rows($ticket)){ $t = mysql_fetch_array($ticket); if($t['userid'] > 0){ $user = mysql_query("SELECT f.id, v.value FROM `tblcustomfields` AS f, `tblcustomfieldsvalues` AS v WHERE f.id = v.fieldid AND f.fieldname = 'Twitter' AND v.relid = '".$t['userid']."'"); if(mysql_num_rows($user)){ $u = mysql_fetch_array($user); if($u['value'] != NULL || $u['value'] != ""){ $tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret); $message = "@".$u['value']." you have a new support ticket response #".$t['tid']." from @DuckHost ".date("H:i"); $tweet->post('statuses/update', array('status' => "$message")); } // end value check } // end user rows } // end userid check } // end ticket rows } // end function add_hook("TicketAdminReply",1,"reply_twitter"); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.