向Blogger REST API(v3.0)發送DELETE請求,我試圖使用delete method刪除帖子。爲此,我使用下面的代碼:嘗試使用Blogger API刪除帖子會返回「未找到」錯誤
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:如果我將請求發送到以下網址:
# 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_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
}
服務器返回:因此,要獲得授權令牌,我使用下面的JWT聲明組發送請求https://accounts.google.com/o/oauth2/token
{
"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和auth令牌,我建議您使用[cURL](http://en.wikipedia.org/wiki/CURL)手動測試您的查詢。根據結果,你會知道如果問題是你如何建立你的網址或其他東西... – 2012-07-31 13:11:26
@AlexisHuet,謝謝你的建議,但無論如何,我敢肯定,問題不在URL中。當然,問題是「別的」。 – B7ackAnge7z 2012-07-31 14:07:29
您是否用'requests'試過了,看看問題出在您使用的模塊中? – 2012-08-03 12:38:38