Example Webservice / API call- 4 GoogleMaps API services

In the following video I work through connecting for four separate APIs which are all under GoogleMaps.  It is very easy to connect to them with AutoHotkey.  Simply get your own token and then adapt the below code to your needs!

Video reviewing the four GoogleMaps APIs.

AutoHotkey Merchandise-White Stress ball

GoogleMaps Directions API

;~  https://developers.google.com/maps/documentation/directions/
IniRead, API_Key,Auth.ini,API,Key ;read current token
queryString:=QueryString_Builder({"origin":"75 9th Ave New York, NY","destination":"MetLife Stadium 1 MetLife Stadium Dr East Rutherford, NJ 07073","key":API_Key})

Endpoint:="https://maps.googleapis.com/maps/api/directions/" . "xml" ;xml or json

;***********API call*******************
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", Endpoint . queryString) ; "GET" "POST" ; be sure to uppercase
HTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded")
HTTP.Send()
Response:=HTTP.ResponseText
SciTE_Output(Response)
;~  SciTE_Output(sXML_Pretty(Response,"   ")) ;Text,Clear=1,LineBreak=1,Exit=0

;***********query string builder*******************
QueryString_Builder(kvp){
for key, value in kvp
  queryString.=((A_Index="1")?(url "?"):("&")) key "=" value
return queryString
}

GoogleMaps GeoCode API

;~  https://developers.google.com/maps/documentation/geocoding/start
IniRead, API_Key,Auth.ini,API,Key ;read current token

;~  queryString:=QueryString_Builder({"address":"836 Kilbridge Lane, Coppell, TX","key":API_Key})
queryString:=QueryString_Builder({"address":"1600 Amphitheatre Parkway, Mountain View, CA","key":API_Key})

Endpoint:="https://maps.googleapis.com/maps/api/geocode/" . "xml" ;xml or json

;***********API call*******************
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", Endpoint . queryString) ; "GET" "POST" ; be sure to uppercase
HTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded")
HTTP.Send()
Response:=HTTP.ResponseText
SciTE_Output(sXML_Pretty(Response,"   ")) ;Text,Clear=1,LineBreak=1,Exit=0

;***********query string builder*******************
QueryString_Builder(kvp){
for key, value in kvp
  queryString.=((A_Index="1")?(url "?"):("&")) key "=" value
return queryString
}

GoogleMaps Places

IniRead, API_Key,Auth.ini,API, Key ;read current token
Endpoint:="https://maps.googleapis.com/maps/api/place/nearbysearch/xml" ; json or xml
queryString:=QueryString_Builder({"location":"32.9939970,-96.9947992","radius":"1000","types":"food","key":API_Key})

API_Call(Endpoint,queryString)
;******************************
API_Call(Endpoint,queryString){
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", Endpoint . queryString )
HTTP.Send()
Response:=HTTP.ResponseText
SciTE_Output(Response) ;Text,Clear=1,LineBreak=1,Exit=0
}

;***********query string builder*******************
QueryString_Builder(kvp){
for key, value in kvp
  queryString.=((A_Index="1")?(url "?"):("&")) key "=" value
return queryString
}

GoogleMaps TimeZone

IniRead, API_Key,Auth.ini,API,Key ;read current token

 ;~  The following example requests the time zone data for Washington, DC, USA, on March 15, 2016, in JSON format:
queryString:=QueryString_Builder({"location":"38.908133,-77.047119","timestamp":"1458000000","key":API_Key}) ;location is lat/long tuple

Endpoint:="https://maps.googleapis.com/maps/api/timezone/" . "json" ;xml or json

;***********API call*******************
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", Endpoint . queryString) ; "GET" "POST" ; be sure to uppercase
HTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded")
HTTP.Send()
Response:=HTTP.ResponseText
SciTE_Output(Response) ;Text,Clear=1,LineBreak=1,Exit=0

 

Example Webservice / API call- Connecting to Zoom & extracting info

For the the AutoHotkey Webinars we use Zoom which is a great, robust, inexpensive tool for hosting online meetings/webinars.  They have a free version which allows you to connect with people for up to 45 minutes!

Below I walk through the following code where I demonstrate how I extract information about users & their meetings.   This is a great example of how many vendors offer APIs to connect to their tools.

IniRead, API_Token ,Auth.ini,API, Token
IniRead, API_Key   ,Auth.ini,API, Key
IniRead, API_Secret,Auth.ini,API, Secret

;~  EndPoint:="https://api.zoom.us/v1/user/list" ;get list of users under your account
;~  EndPoint:="https://api.zoom.us/v1/meeting/list" ;get list of meetings for a given user
EndPoint:="https://api.zoom.us/v1/meeting/get" ;get specific meeting info
;~  QueryString:=QueryString_Builder({"api_key":API_Key,"api_secret":API_Secret,"data_type":"XML","host_id":"pPzEua3eSDerCD2WO3JbUg"})
QueryString:=QueryString_Builder({"api_key":API_Key,"api_secret":API_Secret,"data_type":"XML","id":"693773857","host_id":"pPzEua3eSDerCD2WO3JbUg"})

;********API call**********************
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1") ;Create COM Object
HTTP.Open("POST", EndPoint . QueryString) ;GET & POST are most frequent, Make sure you UPPERCASE
HTTP.Send() ;If POST request put data in "Payload" variable
Response_data:= HTTP.ResponseText ;Save the text that is returned
SciTE_Output(Response_data) ;Text,Clear=1,LineBreak=1,Exit=0

;***********query string builder******************* 
QueryString_Builder(kvp){
for key, value in kvp
  queryString.=((A_Index="1")?(url "?"):("&")) key "=" value
return queryString
}

Video walking through developing the Zoom API call

Web Scraping with AutoHotkey- Data Extraction & emailing to colleagues

web scraping with AutoHotkeyI regularly have to go to login to a website, navigate to a certain page, extract data and then place it into Excel, then email the files to my colleagues.

This video demonstrates how quickly and easily it is done when you program some web scraping with AutoHotKey.  Somehow I lost the audio track however you can still see what is going on.  Also, some of it happens so fast it looks like I sped up the video but it is real-time.  🙂

Demo video of Web Scraping with AutoHotkey and emailing to colleagues

If you’re new to scraping you can see my earlier post here which gives a good review as well as a program that helps write the AutoHotKey code.

Example of Web Scraping- Automating Exporting of contacts from Lexis Nexis

Example of Web Scraping

Example of Web Scraping– Automating the Exporting of Data from Lexis Nexis

A few years back Lexis Nexis had access to Jigsaw (a sales list provider).  They had built in restrictions which allowed for exporting up to 1,000 contacts at a time.

Using AutoHotKey I was able to automate the exporting of contacts from Lexis Nexis into a great format.   All-told I exported over 4 million business contacts including their Name, job title, job function, email address, phone number, company name, company revenue, company NAIC code and SIC codes and much more!  It was quite a score and I was in love with Web Scraping  from then on!

Example of Web Scraping with AutoHotkey