Use oauth2 to retrieve Google Places client_id - javascript

Is it possible to retrieve the Google Places client_id using oauth2? I am able to retrieve Google+ information including the id and Google+ profile url, but I need a way to tie the oauth2 user to the Google Places "client_id".
I have been able to include the Places scope which is listed in the oauth2 popup and asks the user for permission to access the resources, but cannot figure out how to retrieve the authenticated user's client_id.
Scopes:
var scopes = 'https://www.googleapis.com/auth/plus.me https://maps.google.com/maps/feeds/ https://www.googleapis.com/auth/places';
Google+ API Load
Although I can successfully retrieve plus data, the places api does not seem to expose any data. Here is what I have tried:
function makeApiCall() {
/* the plus api does retrieve data, but a similar call to places does not
gapi.client.load('plus', 'v1', function () {
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function (resp) {
$(".google-signin").find("img").attr('src', resp.image.url).css('height', '32').css('width', '32');
$("#login-msg").text('Welcome: ' + resp.displayName);
$("img.vote").css('visibility', 'visible');
});
});
*/
gapi.client.load('places', 'v1', function () {
debugger
// the gapi.client does not contain a "places" object
var request = gapi.client.places.get({
'userId': 'me'
});
request.execute(function (resp) {
debugger
});
});
}
Any clarity on this issue is appreciated.
CLARIFICATION EDIT
Perhaps I did not make myself clear. The Google Places API encourages the creation of Events, which are associated with specific Places (of business). We are generating lists based on Google Places API search and details responses (prototype at top-60.bunkerhill.com follow one or more links) We would like businesses to be able to add Events to their associated listing, but cannot allow this without first somehow associating the Places Detail response data with a Google Sign-On; or am I missing something important here?
So the question is "Can a user sign-in to any available Google OAuth API that provides some data which can be used to associate the user with a Places Details entry?

The Google Places API is not the same as the G+ API.
Check out https://developers.google.com/places/documentation/ for instructions on accessing Places data (note that you do not use OAuth for this API - you just include the key from developers.google.com/console in your http request).

Regarding the clarified question: No, the Places API authentication and authorization for creating Events is only via the developer (and your API key), and never the end user who may interact with your application.
For this specific example, you (the developer) can create Events that are associated with a Place, but it would be incumbent on you to make a further association of which end user you wanted to associate with the creation of that Event, and store that metadata within your application if you cared to do so.
Is there a reason having the Places API itself understand this relationship that would be a benefit to your application?

Related

How to make Google Calendar API Requests using javascript and a service account?

I followed this quickstart tutorial for the Google Calendar API using javascript in my web application. As I need the possibility to show Calendar data on the webpage without user login, I need to implement API calls using a Service Account. Unfortunately I cant't find any good tutorials or explanations for doing so in javascript and since I am fairly new to the subject of API programming I kind of need some guidance.
Ty in advance.
Using Service account on client side is not secure. You may want to switch to a server side implementation for that. Assuming you are familiar with javascript I suggest to follow NodeJS implementation from here.
To create Service Account select service account after step 1->a.
Refer this image for option.
To use Service Account replace the authorize() logic with this
var email = credentials.client_email;
var key = credentials.private_key;
const jwt = new google.auth.JWT(
email, null, key, SCOPES
);
jwt.authorize((err, data) => {
if (err) {
console.error(err);
throw err;
}
console.log('You have been successfully authenticated: ', data);
callback(jwt);
});
As you are using Service Account you also need to create a calendar in your Gmail account to use. Then go to settings and select Add People to share it with client_email from your json, then use your Calendar Id (from Calendar settings) in API Call replacing primary

Google one-tap sign-in/sign-up, Access personal Data

I just started using google on-tap sing-in/sign-up in my new app.
It works perfectly except that I don't know how can I ask user permissions to access scoped data?
client.verifyIdToken(
token,
CLIENT_ID,
function(e, login) {
var payload = login.getPayload(); // <-- payload just containt name,email and picture. I want more
var userid = payload['sub'];
});
You can use Google Sign-In to authorize more scopes. Pass the email address of the account returned by One-Tap as the login_hint parameter to the gapi.auth2.init call, then call gapi.auth2.getAuthInstance().signIn() so that the user can grant access to the other scopes your app require.
You can also use gapi.auth2.authorize for One-Off authorization (if you use gapi.client to perform requests to Google APIs, you generally want to use init/signIn).

GET request to the Google calendar API

Is it possible to make a GET request to the Google calendar API?
I am using AngularJS to create GET request. But it is not important for me how I will send a GET request(with jQuery, Angular etc.). I am interesting in response.
test.controller('TestCtrl', function ($scope, $http) {
$scope.title="I WANT TO MAKE A REQUEST";
$http.get('https://www.googleapis.com/calendar/v3/calendars/'{{calendarid}}'/events?key='{{apiKey}}').success(function(data){
$scope.tests= data;
});
here is a screenshot of my variables calendarid and apiKey values
Maybe I am doing something wrong? Or you can suggest something? Any answer will be appreciated!
P.S. Please say if you need more details.
Since you a user's calendar, you will need to authenticate with either an OAuth Client or a service account (i.e. a robot user) rather than an API key. The OAuth Client ID that you pointed out is different from the calendar ID. The easiest way to find the calendar ID is to make a calendar list call.
I recommend checking out this getting started guide on how to use the Google API JavaScript library to look up calendar data.

How to allow users to see my Google Analytics chart data without undergoing authentication/Sign In process

I am using the Google Analytics Javascript library to let users view a GeoMap of the particular page they are on. However, everytime they attempt to do so, thye have to go through an authentication process only to have my data displayed on my page. How can I find an alternative to this. I only want to embed my Analytics data through a visualized graph on my page so that all anonymous viewers can see it. This is the code where the process takes place.
google.setOnLoadCallback(init);
/**
* This is called once the Google Data JavaScript library has been loaded.
* It creates a new AnalyticsService object, adds a click handler to the
* authentication button and updates the button text depending on the status.
*/
function init()
{
myService = new google.gdata.analytics.AnalyticsService('charts_sample');
/*
this is essentially the line I want to replace. It anonymously
tries to access my viewer's account.I want to set this scope such as it
address the URI of my Analytics account
*/
scope = 'https://www.google.com/analytics/feeds';
/*
if the above scope is altered to my URI then the below unnecessary login
steps will not be required at all. This is the reason why my viewers are
taken to their analytics page which is fundamentally non-existent.
*/
$("authButton").onclick = function() {
// Test if the user is not authenticated.
if (!google.accounts.user.checkLogin(scope))
{
// Authenticate the user.
google.accounts.user.login(scope);
} else
{
// Log the user out.
google.accounts.user.logout();
getStatus();
}
}
getStatus();
}
// gets the account data and then gets the outputs of the requested query
function getStatus()
{
getAccountFeed();
getDataFeed();
}
function getAccountFeed()
{
//Here agsain, I want to modify it access my account's URI
var myFeedUri ='https://www.google.com/analytics/feeds/accounts/default?max-results=50';
myService.getAccountFeed(myFeedUri, handleAccountFeed, handleError);
}
function getDataFeed()
{
var myMapPopularityFeedUri = 'https://www.google.com/analytics/feeds/data?ids=ga%3A53482361&dimensions=ga%3ApagePath%2Cga%3Acity%2Cga%3Acountry%2Cga%3Aregion%2Cga%3Alongitude%2Cga%3Alatitude&metrics=ga%3Avisitors&start-date=2011-12-01&end-date=2011-12-25&max-results=50';
myService.getDataFeed(myMapPopularityFeedUri, handleDataFeed, handleError);
}
Help will be appreciated a lot. Please don't be too critical. Its my first question here. Instead let me know and I will make for my amendments.
Here is a screenshot of what the embed looks like upon my own click, i.e, after GA has
fetched my own data through my account. The geoMap is at the bottom of the page.
It seems the best way is creating of the separate shared (public) feed (report) in Analytics.
Just feed security requires authorization login to view or receive data if the feed (report) was created under personal credentials ... independently to what version OAuth or OAuth2 is used, just if you use request to view data on the site you should use at least API key (for public reports) OR OAuth credentials for personal reports.
look this guide:
Loading an API and Making a Request
or choose any other example from this page:
Google Analytics: Core Reporting API Client Libraries & Sample Code (v3)
Use this nice tool also:
OAuth 2.0 Playground
Generate API key for maps:
Google Maps API Family
Google Maps JS API tutorial:
Google Maps JavaScript API V3
Have you looked at using oAuth2 for the Authorization?

retrieve people/organization information from linked in

hi I am involved in a development of web app, where I have to retrieve information of people or organization from linkedin, dynamically.Suppose user A can search for Organization and user B can search for particular person.
I have gone the throough the linked in API's but was not able to figure it out how to implement it.
I am using Linkedin javascript API
Kindly help me
Using the LinkedIn API is a two-step process. First, get the user of your web app to authorize the app to access their LinkedIn information. This means setting up your app on LinkedIn as follows:
https://developer.linkedin.com/apis
Once you have that set-up, you can then query the LinkedIn API using JavaScript (I assume JavaScript is the language/method you want to use, as you tagged it).
You can adjust the results coming back, per the documentation, by using facets and parameters. For instance, to perform a people search that returns all user's named Barack and their profile headline and summary, you'd do something like:
IN.API.PeopleSearch()
.fields(["headline", "summary"])
.params({"first-name":"Barack"})
.result(function(result) {
alert JSON.stringify(result)
})
headline and summary are profile fields that you specify - you can change these to pull the information you need.
Update - including code to perform a company search.
To perform a Company Search using the JavaScript API, you'd use the IN.API.Raw() method:
IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url))")
.result( function(result) { /* handle result */ } )
.error( function(error) { /* handle error */ } );

Categories

Resources