我希望能从javascript客户端调用/search api。为此,我已经了解到需要一个oauth2访问令牌。
按照Google指南,我必须进入Google Cloud控制台,但是没有Google Cloud Print服务可供订阅。
我应该使用哪个服务来获取API密钥?
我希望能从javascript客户端调用/search api。为此,我已经了解到需要一个oauth2访问令牌。
按照Google指南,我必须进入Google Cloud控制台,但是没有Google Cloud Print服务可供订阅。
我应该使用哪个服务来获取API密钥?
/search
发送请求并确保成功。以下是我成功的方法。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 - 应为您在Google Cloud控制台注册的Client ID的client_id值。
response_type - 此值取决于您计划开发的应用程序类型。对于客户端应用程序(JavaScript应用程序),token应该是该值。有关此主题的更多信息,请参见https://developers.google.com/accounts/docs/OAuth2。
redirect_uri - 应为您在Google Cloud控制台注册的Client ID中指定的重定向URI值。这是用户在被验证时将被重定向到的位置。
scope - 我将其设置为https://www.googleapis.com/auth/cloudprint
。此值将请求授予您的应用程序访问与正在验证的用户帐户相关联的云打印机的权限。
现在,我卡住的部分是尝试使用JavaScript(AJAX)向https://www.google.com/cloudprint/search发送HTTP请求。当我尝试向/search发送HTTP请求时,我会得到以下响应。
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.
/search
的请求的实体(服务器)未配置使用CORS?如果我错了请纠正。/search
。我使用在Web应用程序中进行身份验证时获得的OAuth令牌,并设置了Authorization: OAuth <token>
头进行请求,请求成功。