向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,headers={'Authorization' : oauth_token})
self.response.out.write(result.content)
此刻,我无法理解我做错了什么 – 请求被授权,blogId和postId是正确的 – 但无论如何,服务器返回“未找到”错误.
如果您知道如何解决这个问题,或者您可以提供有用的建议 – 请帮助我.感谢您抽出宝贵的时间和对此事的考虑.
UPD 1:如果我向以下网址发送请求:
# https://www.googleapis.com/blogger/v3/users/{userID}
# https://www.googleapis.com/blogger/v3/users/self
服务器还返回:
{
"error": {
"errors": [
{
"domain": "global","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']
最佳答案