I'm reading this getting started document:
https://github.com/google/google-api-javascript-client/blob/master/docs/start.md
In Option1, the following code is written:
gapi.client.people.people.get({
'resourceName': 'people/me',
'requestMask.includeField': 'person.names'
})
Why .people.people? I want to know the details of this syntax. If I use google drive API, do I write gapi.client.drive.drive.get?
To answer this question lets start with the Discovery services api
The Discovery API provides a list of Google APIs for retrieving a machine-readable "Discovery document" metadata for each API.
The reason we are looking at this is because the Google apis js client library which you are using gapi was generated using the discovery services api. apis-client-generator
Then lets look at the discovery dock for people api
If you check under resources you get
contactGroups
contactGroups.Members
otherContacts
people
people.conversations
Then each resource has a group of methods under and the people resource has a method called get.
So people.people.get is actually {API}.{resource}.{method}
This is just how google chose to build up the API.
Now the google drive api also has a group of resources
About
Changes
Channels
Comments
Files
Permissions
Replies
Revisons
Drives
There is a method called gapi.client.drive.drives.get Which is drive api, drives resource, get method which will return a drives resource.
If your actually after files then its probably more like gapi.client.drive.files.get Which is drive api, files resource, file get method which would return a file resource.
From the API Discovery Document:
For each method defined in the API Discovery Document, a corresponding method is constructed on the gapi.client object.
For example, The People API's methods are under gapi.client.people.
The People API has the methods people.get and people.connections.list.
[T]he generated methods can be called as follows:
gapi.client.people.people.get(...)
gapi.client.people.people.connections.list(...)
You can view API Methods on APIs Explorer.
So .people.people means:
Using the People API-equivalent method people, call the people.get(...) method.
To use the Drive API v3, you would query against gapi.client.drive with your method name. For example, gapi.client.drive.channels.stop(...).
An important note from this answer: you must load the Drive API before using it.
gapi.client.load('drive', 'v3', callback);
Related
I am asking this question after extensively reading Google's recommended approach, but I do have a problem with all these approaches, let me explain the situation.
I use combination of geolocation and geocoding API to know the approximate state location and then display relevant content. The geolocation API needs to be called obviously from the browser to get appropriate geolocation of the user. Google provides HTTP Referrer based restriction for this API. I know someone can easily spoof the referrer and make calls with the same API key. I do not see a huge advantage even though Google recommends this.
On the other hand Google does not allow HTTP Referrer for geocoding API, but it does allow that for the MAPS JavaScript API. But again if you are not using Google maps then using that API is violation of Google's terms. Now google recommends to move the code that uses geocoding web services API to be on the back-end so that your key will be protected. But since ultimately I need to deliver the result to a front-end web application that is publicly accessible and I can only make a browser based Ajax call to first get the geolocation to feed to geocoding, I ultimately need to make an Ajax call to get my geocoding information. Then someone can easily just latch onto my end-point to piggy back on and call the geocoding API as much as they want. So for situations like this I want to know what is the ideal and secured way to deal with. May be there are other APIs that might be an ideal situation for this.
In my case, I am not doing any maps so it's all purely server-side to get latitudes, longitudes and driving distance between two points. This today from Google support which might help and if you're using maps, then the links may provide further insight.
Regarding API restrictions, please note that HTTP referrers will not
work on Geocoding API since HTTP referrers can only be used for client
side services. In other words, Geocoding is a web service API and
should only be used on server-side implementation. IP address
restrictions should be used for web service APIs. However, if you are
using the Geocoding API in a website, IP address restriction would not
work. Please check the suitable restrictions for each API in the
following link:
https://developers.google.com/maps/api-key-best-practices#api_key_table
To make this work, you should create a separate key and use the new
one in your Geocoding API request URL. You may add a restriction to
this key by using an "API restriction", and restrict it to Geocoding
API only. If you don't want to create another key, you may keep using
your current one but make sure to change your implementation and use
the client side Geocoding service from the Maps JavaScript API. In
that case, please refer to this documentation:
https://developers.google.com/maps/documentation/javascript/geocoding
Another suggestion would be to get a static IP address from your ISP,
especially if you are planning to use it on a public website. For
development purposes, a sound solution would be to get three separate
keys: one for the staging and tests, another for server-side requests
and a third one for client-side requests. That way, you are making
sure your API key is protected.
I would like to access the adwords API through a simple single page web application using javascript. I would like to dynamically stop and start some of my adwords campaigns.
I can't seem to find any documentation on the REST endpoints for the API - only documentation for the various libraries.
Is it possible to do this through javascript only?
The current Adwords API is a SOAP-based interface, so there are no REST endpoints to use. It's of course still possible to construct SOAP messages and call operations without using one of the provided libraries.
Having said that, the next evolution of the API (the "Google Ads API") will support both gRPC and JSON REST-based communication, which would probably fit your scenario better. It's not yet ready for production use, however.
I am using google shortener to generate a short URL, the long URL doesn't have any secret data, also the website is fully public.
there is any risk to put my API key in the source code for my app
You probably don't want to do that. If you put the API key in the source code, others will be able to call the Google API as you. From the getting started doc:
"By default, your registered project gets 1,000,000 requests per day for the URL Shortener API (see the Developers console for more details)."
This exposes you to a denial of service - if a malicious entity decides they don't like you, they can grab your source, make 1M short URL requests as you, and you will be unable to make the requests yourself.
I am not able to find google documentation where all valid possible operation url per scope are mentioned?
I am consuming google API, using oauth 2.0 by Httpclient ie without using google api client jar or dependency.
To fetch Users profile I set emailId profile in scope and made a get request to https://www.googleapis.com/oauth2/v1/userinfo?access_token=XXX using HttpClient,this is working.
There is a page where all scopes are mentioned but unable to find list of possible operations for particular scope.Please help me into this.Thanks!
On the page describing scopes, if you click on the title of a scope section, say the Calendar API, you are brought to that API's home page. From here you can got to the guides tab and follow the quick start for the language of your choice (which Google encourages since their client libraries tend to do a lot of the work for you), or go to the reference tab and view the available endpoints. From here you can send your access token as described here
As far as which scope applies to which endpoint, I assume view and read only scopes will probably only work for GET requests, while other manage scopes will probably encapsulate the other endpoints. Apart from that assumption, I don't know if Google has the scope exactly lined up with the endpoints they are valid for.
Is there a way to get Email/Website of a particular place using Google Places API? If this is not possible is there a way other than using Google API?
To retrieve a places website address using Google Places API, you could perform a Places Autocomplete Request with the input parameter value set to the name of the place: e.g.input=Amoeba
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Amoeba&sensor=false&key=your_api_key
Then using the reference from the response you could perform a Places Details Request: e.g.
reference=ClRMAAAAVzPUTLym999EXs4mKkpTqEmzX0a2kfXCUs4enTvWMHDd06VLvlzsGOdfrRd2QvkiRWs4sNkraAAJlMdytt4O4kYGoJZn4ENL5Ig5QYyeJmMSECDOGMO1MnDFtqzdqD8oDk0aFJr8_s-Y946QOz24YubPUsmoC2vl
https://maps.googleapis.com/maps/api/place/details/json?reference=ClRMAAAAVzPUTLym999EXs4mKkpTqEmzX0a2kfXCUs4enTvWMHDd06VLvlzsGOdfrRd2QvkiRWs4sNkraAAJlMdytt4O4kYGoJZn4ENL5Ig5QYyeJmMSECDOGMO1MnDFtqzdqD8oDk0aFJr8_s-Y946QOz24YubPUsmoC2vl&sensor=false&key=you_api_key
This would return the details for Amoeba including if available, the parameter website which would contain the places website address.
Google Places API provides Details requests and responses using your API key.
The tag allows for the google places url for that places
e.g.
http://maps.google.com/maps/place?cid=10704550479004381649
If you wish to harvest website, fax and opening hours information, it can only be done here.
There is no direct api in the Google Places API that will provide that info.
Just as addressComponents are part of the Details response, i assume tags will be added to the Place Details responses from the API to address this problem.
I have been trying to use Google Places API, and I have successful queries, fetching Places details, which has all the address information for the place I want to find, but ironically, there is NO WEBSITE attribute in the returned JSON!
The first version of Local search was MUCH better, and always accurate for searches when you know the business name.