当前位置: 首页 > 知识库问答 >
问题:

Google OAuth令牌请求返回“invalid_client”:“未授权”

齐浩淼
2023-03-14

试图让OAuth2谷歌登录工作,这是我的应用程序发出的原始请求

client_secret:A1B2C3D4E5F6G7H8I9J0K1L2M

code:1/A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6Q7R8S9T0U1V

grant_type:authorization_code

redirect_uri:http://localhost:5000/callback/google/

这是回应:

状态:401未经授权

{
    "error": "invalid_client",
    "error_description": "Unauthorized"
}
    null

对此的帮助将不胜感激。我试图在我的应用程序中设置OAuth2支持的“用X登录”功能,已经让脸书和推特没有问题地工作,也想让谷歌工作,但如果我不能解决这个问题,我恐怕我将不得不放弃谷歌Auth。

共有1个答案

杭永安
2023-03-14

无效客户端意味着您正在使用的客户端id或客户端机密无效。它们必须是你从谷歌开发者控制台下载的。

提示:您可能需要考虑使用Google python客户机库,它可以帮您完成所有繁重的任务。

from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']

def main():
    """Shows basic usage of the Drive v3 API.
    Prints the names and ids of the first 10 files the user has access to.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('drive', 'v3', credentials=creds)

    # Call the Drive v3 API
    results = service.files().list(
        pageSize=10, fields="nextPageToken, files(id, name)").execute()
    items = results.get('files', [])

    if not items:
        print('No files found.')
    else:
        print('Files:')
        for item in items:
            print(u'{0} ({1})'.format(item['name'], item['id']))

if __name__ == '__main__':
    main()
 类似资料:
  • 两天前,我们的贝宝整合出了问题。不幸的是,尝试联系贝宝支持已经证明没有帮助(没有回复在2天),所以我会尝试我的运气,在这里。 谢谢!

  • 我使用springfox 2.9.2我有这样的api: 女巫来自身份验证服务器。我尝试在swagger中首次调用此服务器,并将其传递给像上面这样的控制器请求。所以我做 在Swagger ui上,授权调用成功返回了令牌,但它没有将令牌添加到请求头中。它会产生 如果我像这样设置令牌:

  • 为了发送和检索信封,我正在将我的应用编程接口后端与文档签名集成。我正在使用JWT Grant流。认证选项 在DocuSign开发环境中,我能够使用JWT流和DocuSign C#SKD检索访问令牌。然后我需要调用endpoint,以检索用于调用Docusign的基本uri字段。 当我提出GET请求时https://account-d.docusign.com/oauth/userinfo,包括授权

  • 我在自己的Web API上使用Oauth2,在Web应用程序上使用ASP.NET C#来使用该API。在我的web应用程序上,我正在进行HttpWebRequests。当我的访问令牌过期时,我调用一个方法“refreshToken”,该方法发出请求以获取新的访问令牌。这工作很好,没有问题...除了我得到的响应包含一个新的刷新令牌???我在等新的访问令牌。我甚至认为在没有再次传递凭据的情况下这是不可

  • 问题内容: 因此,我尝试使用以下jQuery代码向Stack Exchange API发出请求: 但是,当我在FireFox或Chrome中打开机器上的文件并发出请求时,出现此错误: 我不知道发生了什么事。我知道Stack Exchange API使用Gzip压缩其响应,这会引起任何麻烦吗? 问题答案: 您必须设置一个非常规参数才能使SO API正常工作。而不是常规的,您需要传递一个参数。 此外,

  • 我试图生成一个access_token和refresh_token访问谷歌电子表格API。我使用了APIhttps://www.googleapis.com/oauth2/v3/token?code=