Skip to content

Instantly share code, notes, and snippets.

@dade80vr
Last active April 6, 2022 06:56
Show Gist options
  • Select an option

  • Save dade80vr/5215da0ff9898fb00855e409b53d04fe to your computer and use it in GitHub Desktop.

Select an option

Save dade80vr/5215da0ff9898fb00855e409b53d04fe to your computer and use it in GitHub Desktop.
Bash script to find phone number by given query using Google Places API
#!/bin/bash
# Bash script to get phone number by name using Google Places API
# By Davide Permunian - https://github.com/dade80vr
# Last update: Dec 13, 2018
# Usage: ./getphone.sh "your query"
# Please change <your_api_key> - See https://developers.google.com/places/web-service/intro
apikey="<your_api_key>"
querystring=$(echo "$1" |sed 's/ /%20/g')
json1=$(curl -s -X GET "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input="$querystring"&inputtype=textquery&fields=place_id&key="$apikey)
google_reply1=$(echo $json1 | jq '.status' | tr -d \")
place_id=$(echo $json1 | jq '.candidates[0].place_id' | tr -d \")
echo "Google 1st call reply: "$google_reply1" ==> place_id: "$place_id
json2=$(curl -s -X GET "https://maps.googleapis.com/maps/api/place/details/json?placeid="$place_id"&fields=formatted_phone_number&key="$apikey)
google_reply2=$(echo $json1 | jq '.status' | tr -d \")
formatted_phone_number=$(echo $json2 | jq '.result.formatted_phone_number' | tr -d \")
echo "Google 2nd call reply: "$google_reply2" ==> formatted_phone_number: "$formatted_phone_number
@shimonm
Copy link
Copy Markdown

shimonm commented May 18, 2020

Thanks you, works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment