Vic*_*tor 5 python api blogger
向Blogger REST API(v3.0)发送DELETE请求,我正在尝试使用delete方法删除帖子.为此,我使用以下代码:
api_uri = 'https://www.googleapis.com/blogger/v3/blogs/%s/posts/%s' % (blogId, postId)
result = urlfetch.fetch(url=api_uri,
method=urlfetch.DELETE,
headers={'Authorization' : oauth_token})
self.response.out.write(result.content)
Run Code Online (Sandbox Code Playgroud)
但服务器返回:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我可以使用以下代码检索有关此帖子的信息:
api_uri = 'https://www.googleapis.com/blogger/v3/blogs/%s/posts/%s' % (blogId, postId)
result = urlfetch.fetch(url=api_uri,
headers={'Authorization' : oauth_token})
self.response.out.write(result.content)
Run Code Online (Sandbox Code Playgroud)
此刻,我无法理解我做错了什么 - 请求被授权,blogId
并且postId
是正确的 - 但无论如何,服务器返回"未找到"错误.
如果您知道如何解决这个问题,或者您可以提供有用的建议 - 请帮助我.
感谢您抽出宝贵的时间和对此事的考虑.
UPD 1:如果我向以下网址发送请求:
# https://www.googleapis.com/blogger/v3/users/{userID}
# https://www.googleapis.com/blogger/v3/users/self
Run Code Online (Sandbox Code Playgroud)
服务器还返回:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
Run Code Online (Sandbox Code Playgroud)
UPD 2:我忘了说我正在使用OAuth 2.0进行服务器到服务器应用程序.因此,为了获得授权令牌,我发送请求以https://accounts.google.com/o/oauth2/token
使用以下JWT声明集:
jwt_claim_set = {
'iss' : '{id}@developer.gserviceaccount.com',
'scope' : 'https://www.googleapis.com/auth/blogger',
'aud' : 'https://accounts.google.com/o/oauth2/token',
'exp' : expire,
'iat' : timestamp
}
Run Code Online (Sandbox Code Playgroud)
服务器返回:
{
"access_token" : "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
"token_type" : "Bearer",
"expires_in" : 3600
}
Run Code Online (Sandbox Code Playgroud)
并定义变量oauth_token
,使用:
data = simplejson.loads(result.content)
oauth_token = data['token_type'] + ' ' + data['access_token']
Run Code Online (Sandbox Code Playgroud)
您确定正确使用 OAuth2 吗?在我看来,您没有正确登录,这就是您收到这些错误的原因。
使用 Google OAuh2 Playground (https://code.google.com/oauthplayground/) 尝试相同的查询,看看会发生什么。