Getting Started With Google Maps Places (New) API In Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey how guys all right so in this video I'm going to show you how to use Google Maps places new API in Python so Google Maps has two version of the places API and let's go into the documentation now if we look at the left hand side we have two places apis one is the uh I'll say this kind of like the Legacy API and the other one's going to be the new generation API with the Legacy places API you can use an API key to connect to the API inpoint but with the Next Generation place this API it's actually a lot more complicated uh than and if we look at the supporter platforms and the documentation is supports Android iOS JavaScript and web service and for this tutorial I'll be uh showing you how to connect to the places API new API using web service now let's look at the setup for the new places API for the places API new I'm going to just name this as places API new the API only supports o of 2.0 for authentication and basically what that means is that we can make a request code to the API but we have to go to the O2 Authentication Protocol I'm going to cover four apis that is part of the new places apis Ona I'll cover places details nearby search text search and autoc complete I know the place foros API has some issues but essentially with this API you are getting the photos infection individually rather than your batch I think this going to be ABM going to cover from the documentation now in terms of the pricing you get 00 credit to use every month and that's going to be for every single Google Maps product everything you see here under the products those will be under the $200 credit that you can uh use now diing into the tutorial so first navigate to Google Cloud console by going to console. cloud.google.com if I a new user simply create account is free then we need to create a project on the top click on the drop down and if you don't have a project simply create a new project now here I'm going to uh choose one of my projects and to use all of two to authenticate first you want to click on navigation menu then go to apis and services and here you're going to see all op consent screen you need to set out the consent screen page first now because I already have a consent screen set up so simply follow the instruction and set up the consent screen and once you create the consent screen page we need to create all up to credential so click on credentials and you can navigate to the credentials Page by going to apis and services then click on credentials let me increase the zoom on the top click on create credentials and choose all of client ID for the application type I'm going to choose D app then give the account name I'm name this as map demo and create the account now it's going to display the client f.y to.com now we need to download the client file by click on download and save the file in your project folder now here I'm going to name the file client secret. Json you can also download the client file by click on the download icon here all right so let's go in the launcho terminal now to connect to places a API new uh API service we need to install Google python client library and can find the P command from Google Sheets API page now going to copy the P command and run the installation and once we install the libraries show this one more library that I'll be using and going to be the python dob python package and once we install all the libraries as well as download the client file we can now dive into the examples from Google Maps API is documentation I want to go to reference on the left hand side going to see two different types of reference one's going to be uh rest reference and that's going to be using rest API and the other one is going to be R PC and that's going to be a specific python package not python package a specific package and currently I don't think RPC supports python so we have to use R API now start with something easy let's start with search text and I shouldn't uh close the Tab and let me put that back now the CIS TX API here is corresponding to the text search API and let me launch my vle and me delete this folder here oh and before we diving into the python examples I created a module called Google apis inside the module I have a function called create service now this function is a pretty important function and using this uh create service function we'll be able to connect to different apis like Google Sheets API YouTube API Gmail API in this case we can also use this function to connect to the places API new API in down the source code from the link in the description below let me go ahead to create a python script Code maps text search. now let me go ahead to import the create service function next we need to specify the apis information so first we need to create a variable to point to the client secret file that we just download then we need to specify the API name API version and the Scopes then using the create service function we need to provide the client secret file API name API version and Scopes now let me go ahead and create the service aure oh and for the first time you need to authenticate your account on this page simply click on advance and click on this link to proed now here we need to go permission to the app so click on continue and when you see this message the authentication flow here is complete you may close this window and we can close the tab now if I print the members of the service object from the output you should see the places uh endo and phone service. paces and let's print the members again oh this should be a method now if you look at the output again we not have these six elements now each element represent an API so for auto complete it reference to the aut complete API here and for the search nearby API this is going to reference the nearby search API if you want you can also go back to the documentation and can probably guess the association so photos is going to be Place photos get is going to be place the details and I don't see close reference to any API so just this fire and for this lesson I'll show you uh two examples since the usage is basically the same across all apis all right so I'll pick search text and get now here I'm going to put my Cod editor and the documentation set by set I want to go back to the documentation and to be honest this is probably one of the most confusing apis you'll probably have to use in terms of within Google's apis now here let's go into search text document reference now when we are providing parameters we need to provide the parameters as a request body juston option and on top of that there are other additional parameters that is not part of the request body such as uh test quy this going to be the search stream that you're going to provide to perform the search and this one is require but the rest is going to be optional Now link all the links in the description below let me go ahead and insert the search option that places and I name this response now first I need to insert the query let's name this as Curry andless I want to search for Raman places and it's going to be the curry string and for the origion code I'm just going to use us and here we can also set the rank prence and it's going to be a in value and to set the ranking order and let's use relance so this going to be a text string of the ranking type then we have other additional parameters and for those I'll let you to go to those uh par sign on I want to cover the request body actually you know what I think I made a mistake so this should go into the request body now let me do this I'm going to create a request body alra and it's going to be the parameters so first we need to write the test query which is going to be the search query then I'm going to specify the region code it's going to be us now for something more complex like location restriction or location bias with those you need to provide a next dist object to set the parameters value and actually let me replace this with location restriction since I already have a CO now if we look into the location restriction object here let me look at the description here location restriction is going to be the region I want to search and it's going to be the ltitude longitude location they need to set the radius and we look at the document reference for the location restriction this is going to be the object type and I guess uh for let's see for search text I need to set that to a rectangle then need to dive into the next object then need to set the dimension and it's going to be low and it's going to be high I'm simply going to just grab the l two and longer to from the from this example here now going back to the previous page we don't need to provide the radius and I know for nearby search this is going to be Circle not rectangle and the last one is going to be price levels and for this one we can provide a list of in values so we can look at price level so we can either choose uh free service inexpensive moderate expensive and Fa expensive and iume for now this is going to be AB I'm going to provide now we can supply the request body to the body parameter then we need to insert the execute me again now if I run here let me go back now if I run this code here oh me take a look and I think it's going to be uh this one here that cing the issue let me go back okay so I see the issue here I should take out the the C bracket all right so let me try again and this time I'm able to create the request body now if I run the request okay uh sorry so this should be places Follow by search text then the body will go here now let me try again now if I run the request you're going to uh run into this area right here the Field Mass is required parameter and this is where a lot of people run into difficulty trying to figure out how to use the API and this actually took me a while to figure out so if we go back to the documentation and if we go into workway place data choose fields to return using the Next Generation places API you need to specify the fields if you want to return everything you can simply insert the wall car and here I'm going to insert Fields down the wild card symbol now this time if I run the request and that should go to oh price level is not supported so I guess for the text search API the free price level is not supported now I'm just going to use a very expensive okay now this time I'm not running into any air if I print the response and we now get a dictionary that looks like these and to return the items if we PR the keys it will be on the places key and now name the outputs places list now we can look at the first record now this going to be the ination that tied to the printer that we specify in the request body now one solution to import the data set or to organize the data set into a more manageable manner is using pendas and this will be P install pendas and let me install the libraries first all right so let's go back now I can use pandas to load the data set as a data frame oh now I can export the table as a CSS file now if we go ahead and open the file now we can easily exam the content so from the data set we have information such as the phone number address and if want to extract the photos and I'll show you a second I want to locate the name field it should be on the give me a second I'm going to autoit accounts I guess the name of the place is somewhere let's look at the photos first so if we look at the photos column and this is going to be the photos that are tied to the uh restaurant or business and the places photos API is essentially using using Place ID to retrieve the photos individually rather than as a batch I want to just quickly uh look for the business name okay so uh it is actually right here under display name so make going to normalize the table and I'll go back now instead of using pd. data frame I'll use the normalize just normalize function and I'll provide the list and I'll export the data frame now this time if we look at the table again now because everything is normalized we can view all the counts uh this time individually now if I look for name the display name count is going to be by itself let's go to the next example and I'll name the file let's do Maps search show details I'm simply going to copy this code block to the new uh example Now using the git API or the uh places details API Now using this API we can retrieve addition information from the uh Place such as the reviews and couple other sense let's take a look if we look at the response body and these are all the fields from the response so we have payment options parking options view options and so on so we have a lot more fields that we can work with and to use the get API so service. places. and I thinkc for the places API we don't need to provide the request body in that's why I want to show you this example the only thing we need to provide is the place ID and it's going to be the format then we have other additional parameters like the language code region code and so on now here I'm going to insert the name parameter and for the place ID I'll go back to the spread sheet and from the name field so these are going to be the place ID and I'll grab maybe this one here and again we need to insert the fields and I'll go ahead the run the crest and I'll grab uh these two lines here and I think the keys should be let's take a look okay I forgot to insert the SQ meian now if I point the keys now this time we get a addition but uh each key is going to reference uh each field other than a list of Records we can paste the response directly to the Json normalized function and this will be place this is detail details and I'll export the C file and we now have the business fion that tied to this ID here so just quickly go to the metad data or Fields so we have a lot more uh information that we can use to analyze the business now this going to be I'm going to cover in this tutorial and hopefully you guys find this video useful if you find this video useful please don't forget to like the video and subscribe to the channel I'll see you guys in the next video
Info
Channel: Jie Jenn
Views: 2,429
Rating: undefined out of 5
Keywords: python, google maps api, google maps places new api, google maps places api
Id: lVtu-JWmHOo
Channel Id: undefined
Length: 26min 41sec (1601 seconds)
Published: Sun Apr 21 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.