使用Python调用Blogger API发布内容时遭遇400错误(redirect_uri_mismatch)的问题求助
使用Python调用Blogger API发布内容时遭遇400错误(redirect_uri_mismatch)的问题求助
我已经熬了整整24小时了,用Python调用Blogger API发布文章这事怎么都搞不定,实在没办法来求助了😭
按照官方文档的思路写了认证和调用的代码,但每次走到认证环节就弹出400错误,提示redirect_uri_mismatch。我反复检查了OAuth凭据里的重定向URI,试了好几种配置都没用,现在完全卡壳了。
贴出我目前写的代码:
import os import google.auth import google_auth_oauthlib.flow import googleapiclient.discovery import googleapiclient.errors # 我下载的OAuth 2.0凭据文件路径 CREDENTIALS_FILE = 'cred.json' # 要发布的Blog ID(从Blogger后台URL里找到的) BLOG_ID = '2045983628813599998' def authenticate_blogger_api(): """认证并创建Blogger API客户端""" # 定义需要的权限范围(读写文章) SCOPES = ['https://www.googleapis.com/auth/blogger'] # 从本地文件加载凭据 flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(CREDENTIALS_FILE, SCOPES) # 启动OAuth 2.0认证流程 creds = flow.run_local_server(port=0) # 创建API客户端 blogger = googleapiclient.discovery.build('blogger', 'v3', credentials=creds) return blogger # 发布文章的函数还没写完,因为连认证这关都过不去 # def create_post(blogger, blog_id, title, content): # # ... 代码还没写完就卡壳了
我已经确认过这些细节:
- cred.json是直接从Google Cloud控制台的OAuth凭据里导出的,文件内容应该没问题
- 已经在Google Cloud控制台启用了Blogger API服务
- 重定向URI试过配置
http://localhost:8080/、http://localhost/这些常见值,但还是报同样的错误
有没有大佬能帮我看看问题出在哪?或者有没有什么容易忽略的细节我没注意到?
备注:内容来源于stack exchange,提问作者karen
相关产品推荐
相关产品推荐

