Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to delete a post using Blogger API returns "not found" error

Sending a DELETE request to Blogger REST API (v3.0), I'm trying to delete a post using delete method. For this I use the following code:

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)

But the server returns:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

However, I can retrieve information about this post, using the following code:

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)

At this moment, I can't understand what am I doing wrong — the request is authorized, the blogId and postId are correct — but anyway, the server returns "not found" error.

If you know how to solve this problem or you can give useful advice — help me please.
Thank you for your time and consideration of this matter.


UPD 1: If I send requests to the following URLs:

# https://www.googleapis.com/blogger/v3/users/{userID}
# https://www.googleapis.com/blogger/v3/users/self

The server also returns:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}


UPD 2: I forgot to say that I'm using OAuth 2.0 for Server to Server Applications. Thus, to get authorization token, I send request to https://accounts.google.com/o/oauth2/token using the following JWT Claim Set:

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
}

The server returns:

{
  "access_token" : "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
  "token_type" : "Bearer",
  "expires_in" : 3600
}

And define variable oauth_token, using:

data = simplejson.loads(result.content)
oauth_token = data['token_type'] + ' ' + data['access_token']
like image 923
Victor Avatar asked Oct 07 '22 02:10

Victor


1 Answers

Are you sure that you're using OAuth2 properly? It seems to me that you're not properly logged in, and that's why you're getting those errors.

Try those same queries using Google OAuh2 Playground (https://code.google.com/oauthplayground/) and see what happens.

like image 59
pyriku Avatar answered Oct 14 '22 11:10

pyriku