【发布时间】:2012-08-07 01:51:28
【问题描述】:
向 Blogger REST API (v3.0) 发送 DELETE 请求,我正在尝试使用 delete method 删除帖子。为此,我使用以下代码:
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)
但是服务器返回:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
但是,我可以使用以下代码检索有关此帖子的信息:
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)
此时,我无法理解我做错了什么——请求被授权,blogId 和postId 是正确的——但无论如何,服务器返回“未找到”错误。
如果你知道如何解决这个问题或者你可以提供有用的建议——请帮助我。
感谢您抽出宝贵时间考虑此事。
UPD 1:如果我向以下 URL 发送请求:
# https://www.googleapis.com/blogger/v3/users/{userID}
# https://www.googleapis.com/blogger/v3/users/self
服务器也返回:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
UPD 2:我忘了说我使用的是OAuth 2.0 for Server to Server Applications。因此,为了获取授权令牌,我使用以下 JWT 声明集向https://accounts.google.com/o/oauth2/token 发送请求:
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
}
服务器返回:
{
"access_token" : "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
"token_type" : "Bearer",
"expires_in" : 3600
}
并定义变量oauth_token,使用:
data = simplejson.loads(result.content)
oauth_token = data['token_type'] + ' ' + data['access_token']
【问题讨论】:
-
考虑到您可能已经检查了 ID 和身份验证令牌,我建议您使用 cURL 手动测试您的查询。根据结果,您将知道问题是您如何构建 url,还是其他什么...
-
@AlexisHuet,感谢您的建议,但无论如何,我确定问题不在 URL 中。当然,问题出在“别的东西”上。
-
你用
requests试过了吗,看看是不是你使用的模块有问题? -
只是删除失败了吗?或者您也有类似的编辑问题?