Google表格更新Api:出现错误[请求缺少必需的身份验证凭据] [英] Google Sheet Update Api : Getting error [Request is missing required authentication credential]

查看:384
本文介绍了Google表格更新Api:出现错误[请求缺少必需的身份验证凭据]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下参数在Postman中调用Google表格更新请求:

I am calling Google Sheet Update Request in Postman with following parameters:

网址: https://sheets.googleapis.com/v4/spreadsheets/ SpreadSheetId /values/ SheetName !A1:D5 请求类型:PUT
标头:授权- MyAccessToken
请求正文:

Url:https://sheets.googleapis.com/v4/spreadsheets/SpreadSheetId/values/SheetName!A1:D5 Request Type : PUT
Headers : Authorization - MyAccessToken
Request Body :

得到回应:

Getting Response :

注意:要更新到电子表格,请按照以下步骤操作:

Note : For Updating into Spreadsheet, I follow these steps :

  1. 使用此链接在Google Api控制台上创建应用程序,然后移至凭据部分.单击创建凭据,然后单击OAuth客户端ID,将应用程序类型创建为Web应用程序.现在离开限制部分.然后创建.现在创建了应用程序.

  1. Create an application on Google Api Console using this link and then move to Credentials section. Click Create Credentials, then OAuth Client ID, Create Application type as Web Application. For now leave the Restrictions Section. Then Create. Now Application is created.

OAuth同意屏幕标签

现在,使用此链接授权API.在右上角,打开设置"图标.选择使用您自己的OAuth凭据为true.在Google Api控制台上的项目中添加客户端ID"和客户端密码".选择范围为 https://www.googleapis.com/auth/spreadsheets (位于Google Sheet Api v4下拉菜单中),然后授权API.

Now, Authorize the API using this link. In the right corner, open the Settings Icon. Select Use your own OAuth Credentials as true. Add the Client Id and Client secret from the Project on Google Api Console. Select the Scope as https://www.googleapis.com/auth/spreadsheets under the Google Sheet Api v4 in the dropdown, then Authorize the API.

如果获取 redirect_mismatch_uri .然后将重定向URI复制到oathPlayground或提示符提示符之前,然后将其粘贴到Google Api控制台中项目的限制"下的授权重定向URI"中.然后将生成访问令牌,

If Get redirect_mismatch_uri. then Copy the redirect URI till the oathPlayground or before the prompt parameter and paste it into the Authorized Redirect URI under the restrictions Section of project in Google Api Console. Then Access Token will be generated,

  1. 获取访问令牌.将此访问令牌复制到我之前定义的请求中.

但是出现错误.我无法找出问题所在. 在此先感谢.

But Getting error. I am not able to figure out the problem. Thanks in Advance..

推荐答案

由于您已经具有刷新令牌,因此可以使用刷新令牌来检索访问令牌.作为示例,它显示了一种如何通过curl使用刷新令牌来检索访问令牌的方法.刷新令牌检索到的访问令牌具有到期时间.请确认.

Since you already have a refresh token, you can retrieve access token using refresh token. As a sample, it shows a method of how to retrieve access token using refresh token by curl. The access token retrieved by refresh token has the expiration time. Please confirm it.

您可以在此处查看详细信息. https://developers.google.com/identity/protocols/OAuth2WebServer

You can see the detail infomation here. https://developers.google.com/identity/protocols/OAuth2WebServer

curl -L \
  --data "refresh_token=### refresh token ###" \
  --data "client_id=### client id ###" \
  --data "client_secret=### client secret ###" \
  --data "grant_type=refresh_token" \
  https://www.googleapis.com/oauth2/v4/token

结果:

{
 "access_token": "### access token ###",
 "token_type": "Bearer",
 "expires_in": 3600
}

下面的curl命令用于检索访问令牌的信息.如果访问令牌的到期时间已经结束,则响应为{"error_description": "Invalid Value"}.如果不是,您会看到以下响应.

Below curl command is for retrieving the information of access token. If the expiration time of access token had been over, the response is {"error_description": "Invalid Value"}. If it's not, you can see a following response.

curl -L \
 --data "access_token=### access token ###" \
https://www.googleapis.com/oauth2/v2/tokeninfo

结果:

{
 "issued_to": "#####",
 "audience": "#####",
 "scope": "#####",
 "expires_in": 1234,
 "access_type": "offline"
}

EDIT1

此示例代码用于将sheet1!A1:C2的范围更新为[["test1","test2","test3"],["test4","test5","test6"]].

EDIT1

This sample code is for updating the range of sheet1!A1:C2 to [["test1","test2","test3"],["test4","test5","test6"]].

curl -L -X PUT \
-H "Authorization: Bearer ### access token ###" \
-H "Content-Type: application/json" \
-d '{"values":[["test1","test2","test3"],["test4","test5","test6"]]}' \
"https://sheets.googleapis.com/v4/spreadsheets/### spreadsheet ID ###/values/sheet1%21a1%3ac2?valueInputOption=USER_ENTERED"

结果:

{
  "spreadsheetId": "### spreadsheet ID ###",
  "updatedRange": "sheet1!A1:C2",
  "updatedRows": 2,
  "updatedColumns": 3,
  "updatedCells": 6
}

这篇关于Google表格更新Api:出现错误[请求缺少必需的身份验证凭据]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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