Web-Design web-design Google, Twitter and Facebook.: Auto Follow and Tweet At someone (Part II) from Google Form

Sunday, February 20, 2011

Auto Follow and Tweet At someone (Part II) from Google Form

Following up from Part I it would seem pointless if all that cool effort of acknowledging your new member via an automated tweet with their name goes unnoticed by the new user! This is however possible if your twitter account pushes alot of tweets, therefore a tweet going unnoticed is possible.

One of the workarounds I've thought about is to tweet @JohnDoe as well as to automatically start following JohnDoe on twitter. That definately improves the odds of him seeing that you've tweeted at him, acknowledging his presence to your online community.
Additionally, you will be able to automatically start following more of your community members on twitter. This will give you a better idea (via their tweets) of who they are and what their interests are. This you may find very useful. As a matter of fact, your community members will feel special knowing that a blog/website that they pay attention to pays attention to them!

The Auto Follow Plan

Include another textbox inside of the google sign-up form which will allow a user signing up to enter their twitter username.

Add this block of code to the script created in Part I

function autofollow(){
       var  requestData = {
      "method": "POST",
      "oAuthServiceName": "twitter",
      "oAuthUseToken": "always"
     try  {
      var lastrow = SpreadsheetApp.getActiveSpreadsheet().getLastRow()
      var twitterUser = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getRange(lastrow, 4).getValue() // The Twitter Username is stored in the fourth column in my spreadsheet hence the use of 4.
      var result = UrlFetchApp.fetch(
          "http://api.twitter.com/1/friendships/create.xml?screen_name="+ twitterUser,
     }  catch  (e) {
    } }

I've now changed the trigger for on-form-submit in google app script, which now runs this my new function called "run"

function run(){

The getRowsContent function has been modified to include this line below the "lastrow = " line.
var twitterUser = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getRange(lastrow, 4).getValue()

as well as the "var msg =" line has been modified as follows

var msg =  "Hi " +  Firstname + ", welcome to Mark-TechSavvy! @"+twitterUser 

Here's the sample form, test it

Resource: Twitter API
Again, here's to putting Social Media to work for you...



Post a Comment