在Postman的Google Analytics API中获取令牌

时间:2018-12-04 07:45:23

标签: google-api postman google-analytics-api

我需要创建请求以从Postman的Google Analytics(分析)API中获取数据。我设法通过Playground平台生成了访问令牌,但是我需要永久刷新令牌(在Playground中我只能生成24小时令牌)。

我试图在控制台API中生成令牌:

  1. 我已经创建了项目
  2. 在我的项目中添加分析API
  3. 生成客户端ID和密码

但是我不知道使用哪个重定向URL。在JSON中生成的默认值为urn:ietf:wg:oauth:2.0:oob“,” http://localhost

我已经通过请求生成了授权码(来自浏览器):

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/analytics&redirect_uri=http://localhost&response_type=code&client_id=XXXX

当我尝试在Postman中用POST请求生成access_token时,发送这样的密钥:

code:XXXXXX
redirect_uri:urn:ietf:wg:oauth:2.0:oob (also tryed http://localhost)
client_id:YYYYY
client_secret:ZZZZZZ
scope:https://www.googleapis.com/auth/analytics
grant_type:authorization_code

出现错误

{
    "error": "invalid_grant",
    "error_description": "Bad Request"
}

我应该如何为邮递员设置补助金?您能帮助我解决问题并理解我做错了什么吗

1 个答案:

答案 0 :(得分:0)

我设法解决了我的问题。应该添加redirect_url https://www.getpostman.com/oauth2/callback