如何从API访问私有电子表格? [英] How to get access to a private spreadsheet from the API?

查看:72
本文介绍了如何从API访问私有电子表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要从Google电子表格API访问电子表格.我已经启用了Google Sheets API并添加了API密钥,但这是行不通的!!! https://sheets.googleapis.com/v4 /spreadsheets/[my_spreadsheet_id]/values/A1?key = [my_api_key]

Hello I need to get access to a spreadsheet from google spreadsheet API. I have enabled Google Sheets API and added API key, but this doesn't work!!! https://sheets.googleapis.com/v4/spreadsheets/[my_spreadsheet_id]/values/A1?key=[my_api_key]

结果是: 403-呼叫者没有权限

The result is: 403 - The caller does not have permission

但是,如果我提供此电子表格的公共访问权限--->可以!!!!

But if I provide public access for this spreadsheet ---> it works!!!

结果是: 200-[正确的请求数据....]

The result is: 200 - [correct requested data .....]

我的问题是: 如何通过API访问私有电子表格?

The my question is: How to get access to a private spreadsheet from the API?

我需要使用php的诸如file_get_contents()之类的功能从我的网站读取和写入订单数据

I need to read and write orders data there from my website using php's functions like file_get_contents()

推荐答案

基本上,您需要按照

无论何时您的应用程序请求私人用户数据,它都必须随请求一起发送OAuth 2.0令牌.您的应用程序首先发送一个客户端ID,并可能发送一个客户端密钥以获取令牌.您可以为Web应用程序,服务帐户或已安装的应用程序生成OAuth 2.0凭据.

Whenever your application requests private user data, it must send an OAuth 2.0 token along with the request. Your application first sends a client ID and, possibly, a client secret to obtain a token. You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.

OAuth 2.0文档中的其他信息,当使用OAuth 2.0访问Google API时,所有应用程序都遵循以下步骤:

Further information from OAuth 2.0 documentation, when accessing a Google API using OAuth 2.0, all applications follow these steps:

  1. 从Google API控制台获取OAuth 2.0凭据.
  2. 从Google授权服务器获取访问令牌.
  1. Obtain OAuth 2.0 credentials from the Google API Console.
  2. Obtain an access token from the Google Authorization Server.

在您的应用程序可以使用Google API访问私有数据之前,它必须获得授予该API访问权限的访问令牌.

Before your application can access private data using a Google API, it must obtain an access token that grants access to that API.

  • 将访问令牌发送到API.
  • 如有必要,刷新访问令牌.
  • 最后,为了帮助您使用PHP进行实施,您还可以添加

    Lastly, to help you with the implementation using PHP, you may also add Authentication and authorization to your list of references. Hope that helps!

    这篇关于如何从API访问私有电子表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆