Last active
April 6, 2022 06:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks you, works great!