Google cloud print API key
Asked Answered
G

1

3

I would like to call /search api from javascript client side. To do so, I have read that I need a oauth2 access token.

Following the Google guide, I must go to Google cloud Console but there is no Google Cloud Print service to subscribe to.

What service should I use to obtain an API key?

Gentilis answered 2/12, 2013 at 16:40 Comment(0)
C
3

I recently started getting familiarized with both Google Cloud Print and OAuth, so I don't know much. I started in the same way that you seem to be starting. That is, by trying to make a successful request to /search. I will describe what worked for me.

After creating the project in the Cloud Console, I went to APIs & auth > Credentials menu item and created a new client ID for a 'Web Application' application type.

For the created client ID, I modified the Javascript Origins and the Redirect URIs appropriately.

Then, I added an anchor to the following URL in my web application so that the user gets directed to the authentication page.

https://accounts.google.com/o/oauth2/auth?
response_type=token&
client_id=<application-client-id>&
scope=https://www.googleapis.com/auth/cloudprint&
redirect_uri=<application-redirect-uri>

client_id - should be the client_id value of the Client ID that you registered in the Google Cloud Console.

response_type - This value would depend on what kind of application are you planning to develop. For client side applications (JavaScript apps), token should be the value. See https://developers.google.com/accounts/docs/OAuth2 for more info on this topic.

redirect_uri - should be the redirect URI value that you specified in the Client ID that you registered in the Google Cloud console. This is where the user will get redirected when it gets authenticated.

scope - I set it to https://www.googleapis.com/auth/cloudprint. This value will request that your app be given access to manage the cloud printers associated with the user account that is being authenticated.

Now, the part where I got stuck is when trying to make the HTTP request using JavaScript (AJAX) to https://www.google.com/cloudprint/search. I get the follow response when I attempt to make the HTTP request to /search.

OPTIONS https://www.google.com/cloudprint/search No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

It seems like the entity (server(s)) that is handling the request to the /search interface is not configured to use CORS? Correct me if I am mistaken.

Now, the way that I verified that I was able to successfully authenticate was by attempting the request to /search in a Java program instead. I used the OAuth token that I got when authenticating using my web app in a java program and made the request with the Authorization: OAuth <token> header set) and the request was successful.

Calen answered 6/1, 2014 at 3:16 Comment(2)
This is crazy, nowhere "googleapis.com/auth/cloudprint" is listed on the google developer page. Thank you for showing that this scope exists :DParadise
@DavidGatti It is absolutely amazing to me that they can try to hide this endpoint from their users.Heda

© 2022 - 2024 — McMap. All rights reserved.