Google云打印API密钥 [英] Google cloud print API key

查看:181
本文介绍了Google云打印API密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从javascript客户端调用/搜索api。为此,我已经读过我需要一个oauth2访问令牌。

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

根据Google指南,我必须访问Google云端控制台,但没有Google云打印服务可以订阅。

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

我应该使用什么服务来获取API密钥?

What service should I use to obtain an API key?

推荐答案

我最近开始熟悉Google Cloud Print和OAuth,所以我不太了解。我开始的方式与你似乎开始的方式相同。也就是说,尝试向 / search 发出成功请求。我将描述对我有用的内容。

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.

在云端控制台中创建项目后,我去了 API& auth > 凭据菜单项,并为Web应用程序应用程序类型创建新的客户端ID。

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.

对于创建的客户端ID,我相应地修改了 Javascript Origins 重定向URI

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

然后,我添加了一个锚点到在我的Web应用程序中跟踪URL,以便用户被定向到身份验证页面。

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 - 应该是您注册的客户ID的client_id值在Google云端控制台中。

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

response_type - 此值取决于您计划开发的应用类型。对于客户端应用程序(JavaScript应用程序),令牌应该是值。有关详情,请参见 https://developers.google.com/accounts/docs/OAuth2 关于此主题。

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 - 应该是您在Google云端控制台中注册的客户端ID中指定的重定向URI值。这是用户在获得身份验证时将被重定向的位置。

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.

范围 - 我将其设置为 https:/ /www.googleapis.com/auth/cloudprint 。此值将请求您的应用程序有权管理与正在进行身份验证的用户帐户关联的云打印机。

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.

现在,我卡住的部分是尝试使用JavaScript(AJAX)发出HTTP请求以 https://www.google.com/cloudprint/search 。当我尝试向/ search搜索HTTP请求时,我收到了以下回复。

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.

似乎正在处理对<$ c的请求的实体(服务器) $ c> / search 接口未配置为使用CORS?如果我弄错了,请纠正我。

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.

现在,我验证我能够成功验证的方式是尝试向 /搜索请求而是在Java程序中使用。我使用了在java程序中使用我的Web应用程序进行身份验证时获得的OAuth令牌,并使用授权:OAuth< token> 标头集)和请求进行了请求成功了。

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.

这篇关于Google云打印API密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆