简体   繁体   English

如何获得刷新令牌?

[英]How to have the refresh token?

I need to use Google Play Android API, i follow a lot of instructions to be connected with the API but I block at one.( Authorization documentation ) Exactly at the step 4 when they say: 我需要使用Google Play Android API,我会按照许多说明与API连接,但我会阻止它。( 授权文档 )正好在第4步时他们说:

Sending a Post with this code: 使用以下代码发送帖子:

grant_type=authorization_code

code=<the code from the previous step>
client_id=<the client ID token created in the APIs Console>
client_secret=<the client secret corresponding to the client ID>
redirect_uri=<the URI registered with the client ID>`

I specify i use serverless and node, how can I do to have my refresh token in https://accounts.google.com/o/oauth2/token please ? 我指定使用无服务器和节点,如何在https://accounts.google.com/o/oauth2/token刷新令牌?

Thank's a lot and sry for my english ^^. 非常感谢我的英语^^。


Sry for this oversight, my serverless it's just that 为了这种疏忽,我的无服务器就是这样

#serverless.yml
service: scrapper-app


provider:
  name: aws
  runtime: nodejs8.10
  region: eu-west-3

functions:
  app:
    handler: index.handler
    events:
      - http: ANY /
      - http: 'ANY {proxy+}'

and my js it's just that too: 而我的js就是这样:


//index.js

const serverless = require('serverless-http');
const express = require('express')
const app = express()

//API

const { google } = require('googleapis');
const oauth2Client = new google.auth.OAuth2(
    IDCLient,
    Secret,
    'https://accounts.google.com/o/oauth2/auth',
);

const scopes = 'https://www.googleapis.com/auth/androidpublisher';

const url = oauth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: scopes
)}


// GET
app.get('/', function (req, res) {
    res.send('Scrapper Rs!');
})



module.exports.handler = serverless(app);

I really dont know how can i do http-post using node and serverless, i succeed with a database (with curl) but not post to an url. 我真的不知道如何使用节点和无服务器进行http-post,我成功使用数据库(使用curl)但不发布到网址。

I didn't used Google Authentication. 我没有使用Google身份验证。 But I think you need to use access_type = offline 但我认为您需要使用access_type = offline

access_type Recommended . access_type 推荐 Indicates whether your application can refresh access tokens when the user is not present at the browser. 指示当用户不在浏览器时,您的应用程序是否可以刷新访问令牌。 Valid parameter values are online, which is the default value, and offline. 有效参数值在线(默认值)和脱机。

Set the value to offline if your application needs to refresh access tokens when the user is not present at the browser. 如果您的应用程序需要在浏览器中没有用户时刷新访问令牌,请将值设置为脱机。 This is the method of refreshing access tokens described later in this document. 这是刷新本文档后面描述的访问令牌的方法。 This value instructs the Google authorization server to return a refresh token and an access token the first time that your application exchanges an authorization code for tokens. 此值指示Google授权服务器在您的应用程序第一次交换令牌授权代码时返回刷新令牌和访问令牌。

To set this value in PHP, call the setAccessType function: 要在PHP中设置此值,请调用setAccessType函数:

$client->setAccessType('offline'); $客户 - > setAccessType( '离线');

Source: https://developers.google.com/identity/protocols/OAuth2WebServer 来源: https//developers.google.com/identity/protocols/OAuth2WebServer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM