Mryqu's Notes


  • 首页

  • 搜索
close

Google Sheets API认证和鉴权

时间: 2016-09-27   |   分类: DataBuilder     |   阅读: 58 字 ~1分钟

玩一把用于Google Sheets API的OAuth2认证,以获得用于Sheets API的访问令牌。

注册Google Sheets应用

首先在Google API Console注册一个应用: Google Sheets API认证和鉴权Google Sheets API认证和鉴权

Google Sheets API鉴权

  • 用于用户登录的HTTPGET请求如下(scope选择了profile、对文件元数据和内容只读访问、对表单和属性只读访问):
    GET https://accounts.google.com/o/oauth2/v2/auth?
    scope=https://www.googleapis.com/auth/spreadsheets.readonly https://www.googleapis.com/auth/drive.readonly profile&
    redirect_uri=urn:ietf:wg:oauth:2.0:oob&
    response_type=code&
    client_id=826380598768-5935tlo90sccvr691ofmp4nrvpthrnn6.apps.googleusercontent.com
    
    首先要求用户登录:Google Sheets API认证和鉴权要求登录后用户的授权:Google Sheets API认证和鉴权返回页面包含授权码:Google Sheets API认证和鉴权
  • 获取访问令牌的HTTPPOST请求包含上面获得的授权码(在创建Google应用时获得的client_id和client_secret):
    POST https://www.googleapis.com/oauth2/v4/token
    Content-Type: application/x-www-form-urlencoded
    
    code=4/-qpp...qA&
    client_id=826380598768-5935tlo90sccvr691ofmp4nrvpthrnn6.apps.googleusercontent.com&
    client_secret=5...r&
    redirect_uri=urn:ietf:wg:oauth:2.0:oob&
    grant_type=authorization_code
    
    Google Sheets API认证和鉴权

参考

Google Sheets
Google Sheets API
Authorize Google Sheets API Requests
Using OAuth 2.0 for Mobile and Desktop Applications
Using OAuth 2.0 for Web Server Applications

标题:Google Sheets API认证和鉴权
作者:mryqu
声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 CN 许可协议。转载请注明出处!

#google# #sheets# #api# #oauth2# #authorization#
Hello Google Sheets API
[Maven] 构建多模块项目
  • 文章目录
  • 站点概览

Programmer & Architect

662 日志
27 分类
1472 标签
GitHub Twitter FB Page
    • 注册Google Sheets应用
    • Google Sheets API鉴权
    • 参考
© 2009 - 2023 Mryqu's Notes
Powered by - Hugo v0.120.4
Theme by - NexT
0%