Showing posts with label VBscript. Show all posts
Showing posts with label VBscript. Show all posts

5/30/13

Getting started with the Mind Body Online (MBO) SOAP API - classic .ASP VBSCRIPT

I've been working on the Mind Body Online API for a few weeks now and finally got things to come together. My challenge was that I'm still coding in classic ASP and all the sample code is PHP - so I had to start from scratch to get things up and running.
The final collection of code is too extensive to post - but as a starter here is the .ASP code that retrieves the test class collection from the -99 test MBO account.

11/21/12

Classic ASP Plotting new visitor location on a google static map

I've been intrigued by the possibility of plotting my web registrants physical location on a map for a while so I thought I'd give it a try and see what was required to make this happen. There are two tools that I ended up using:

1. Google static maps API. Really easy to use - basically just construct the URL to the google map image and you are off and running.

2. Get the visitor location (lat longitude) from their IP address. This was a bit trickier.

Getting started:

1. Visit https://developers.google.com/maps/documentation/staticmaps/ and read up on the creation of a google static map. In my case I stuck with the most basic implementation to keep things easy.


2. After searching for a while I found the best way to get from IP address to location was to use this web service: http://ipinfodb.com/ This service allows you to call an HTTP address and get back physical location information. The basic idea it to call the infodb URL like so:

URL = "http://api.ipinfodb.com/v3/ip-city/?key=" & locationKEY & "&ip=" & UserIPAddress

The result if you simply browse to this address is a semi-colon delimited string containing details like city/state and Lat;Long.

What I did was to create a classic asp function that returned the Lat,Long position like so:

Function getPosition(UserIPAddress)

URL = "http://api.ipinfodb.com/v3/ip-city/?key=" & locationKEY & "&ip=" & UserIPAddress


Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP")
    xmlHttp.Open "GET", URL, False
    xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
    xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
    xmlHttp.Send
    getHTML = xmlHttp.responseText
    xmlHttp.abort()
    set xmlHttp = Nothing   


 arrLocation = SPLIT(getHTML,";")


 strLatitude = arrLocation(8)
 strLongitude = arrLocation(9)

 strCoordinatesTemp = strLatitude & "," & strLongitude

 getPosition = strCoordinatesTemp

END FUNCTION

Once this function was created, all I had to do was iterate through my latest visitors IP address to generate the actual map

'--get most recent 5 locations
sqlGet = "select top(5) pr_ip_address,pr_index from tProfile order by pr_index desc"
set objRsLocations = objConn.Execute(sqlGet)

DO WHILE NOT objRsLocations.EOF


strCoordinates = strCoordinates & "%7C" & getPosition(objRsLocations("pr_ip_address"))
objRsLocations.MoveNext

LOOP

Once that was done - just append the coordinates to the google static maps api url and you are good to go:

<img src=http://maps.googleapis.com/maps/api/staticmap?size=300x300&markers=color:blue%7Clabel:%7C<%=strCoordinates%>&sensor=true>

The result?



8/16/11

using bitly to shorten links classic .asp VBScript

A very easy script to shorten links using the bitly api.




Function bitlyThis(longURL)
apikey = "12345"
url = "http://api.bitly.com/v3/shorten?login=logsitall&apiKey=" & apikey & "&longUrl=" & longURL & "&format=txt"

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""

bitlyThis = xmlhttp.responseText
set xmlhttp = nothing

END FUNCTION


longURL = "http://www.wikipedia.com"

response.write bitlyThis(longURL)


9/10/10

Using oAuth Twitter protocol with VBScript Classic ASP

Update: My twitter feed stopped working when the API was modified October 10, 2012. Luckily changing the code was straight forward and required simply updating the destination for the various post/get statements with the new HTTPS urls as so:

'******************************************************************************
' TWITTER CONSTANTS (add to suite)
'******************************************************************************
'' Const TWITTER_OAUTH_URL_ACCESS = "http://twitter.com/oauth/access_token"
 Const TWITTER_OAUTH_URL_ACCESS = "https://api.twitter.com/oauth/access_token"

'' Const TWITTER_OAUTH_URL_AUTHENTICATE = "http://twitter.com/oauth/authenticate"
 Const TWITTER_OAUTH_URL_AUTHENTICATE = "https://api.twitter.com/oauth/authenticate"



'' Const TWITTER_OAUTH_URL_REQUEST_TOKEN = "http://twitter.com/oauth/request_token"
 Const TWITTER_OAUTH_URL_REQUEST_TOKEN = "https://api.twitter.com/oauth/request_token"
 


'' Const TWITTER_OAUTH_URL_UPDATE_STATUS = "http://twitter.com/statuses/update.json"
 Const TWITTER_OAUTH_URL_UPDATE_STATUS = "https://api.twitter.com/1.1/statuses/update.json" '--updated 10/18/2012

The recent move from REST to oAuth protocol for the twitter API left some developers (like me) scratching our heads. Most of the sample code was written either for PHP or .NET folks - leaving those poor bastards who are still writing VBScript out in the cold.


Luckily for us - Scott at http://scottdesapio.com/VBScriptOAuth/ has put together a great resource for migration to the new platform.

Start with the link above then note that you must:
1. update the _config file with vars supplied by twitter dev site AFTER you register your app. Note that at the time of registration you must provide your call back url (which in the example from scott would be something like http://www.logsitall.com/oAuthASPExample/twitter/callback.asp)

2. update line 40 of base.js file

3. update base.js to refer to your domain, not 127.0.0.1

4. comment out the if statement that seeks to assign window focus to 127.0.0.1 at the end of the base.js file

When you are done, you'll have a system that requests the token from twitter and then uses this token in conjunction with the token's associated with your app to make posts to twitter status feeds.
-->
From a dB standpoint - i think you only need to store the user token - then pair this with the app tokens (which are persistent) in order to make twitter updates on behalf of your users.

Good luck and happy coding.

LogsItAll example:

http://www.logsitall.com/oAuthASPExample/

2/19/10

VBScript Paypal IPN (Instant Payment Notification)

This summary is not available. Please click here to view the post.