在获取 google OAuth 2.0 访问令牌方面需要帮助

问题描述

尝试使用 Google Api 的 REST 调用(不是通过 JavaScript 或任何其他编码语言)创建自动化的博主帖子。我能够使用 api Key 和 Auth2.0 Client 创建所有的 Google。 https://console.cloud.google.com/apis/credentials APi and auth2 由于 Blogger 的 GET 调用使用 API 密钥,因此我可以执行所有获取活动

为了使用 API 发布博客(插入:https://developers.google.com/blogger/docs/3.0/using#AddingAPost),需要访问令牌进行身份验证。要获取用于身份验证的访问令牌,请参阅 https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow#oauth-2.0-endpoints。获得 200 Ok 但没有获得访问令牌。

enter image description here

POST https://accounts.google.com/o/oauth2/v2/auth

POST 数据: client_id=.apps.googleusercontent.com&response_type=token&redirect_uri=http://localhost:8080&scope=https://www.googleapis.com/auth/blogger

PostmanResponse with 200Ok

enter image description here

解决方法

首先它不能使用 api 密钥,因为 api 密钥只能让您访问公共数据,私人用户数据需要授权。使用 Oauth2 为您获取访问令牌。

要获得访问令牌,您需要做一些事情

第一个是创建同意屏幕的链接

https://accounts.google.com/o/oauth2/auth?client_id={clientid}.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/analytics.readonly&response_type=code

然后你需要交换授权码

https://accounts.google.com/o/oauth2/token
code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code

该调用将为您提供访问令牌。

我不太确定你在做什么,但我有一篇博客文章展示了它是如何工作的Google 3 Legged OAuth2 Flow如果你只是想知道如何设置 PostMan 以使用 Google Oauth2 进行授权,我有一个视频,向您展示如何设置这一切 How to set up Oauth2 in PostMan. 如果你真的想了解它是如何工作的,我有一个视频,它会使用 CURL Understanding Google OAuth 2.0 with curl

引导你完成它