Inviando una richiesta DELETE all'API REST di Blogger (v3.0), sto tentando di eliminare un post utilizzando delete method. Per questo io uso il seguente codice:Tentativo di eliminare un post utilizzando l'API di Blogger restituisce l'errore "non trovato"
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)
Ma il server restituisce:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
Tuttavia, posso recuperare le informazioni su questo post, utilizzando il seguente codice:
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)
A in questo momento, non riesco a capire cosa sto facendo male - la richiesta è autorizzata, il blogId
e postId
sono corretti - ma comunque, il server restituisce "non trovato "errore.
Se sai come risolvere questo problema o puoi dare consigli utili - aiutami per favore.
Grazie per il vostro tempo e considerazione di questa questione.
UPD 1: Se invio richieste ai seguenti URL:
# https://www.googleapis.com/blogger/v3/users/{userID}
# https://www.googleapis.com/blogger/v3/users/self
il server restituisce anche:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
UPD 2: Ho dimenticato di dire che sto usando OAuth 2.0 for Server to Server Applications. Così, per ottenere token di autorizzazione, mando richiesta al https://accounts.google.com/o/oauth2/token
utilizzando il seguente JWT rivendicazione 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
}
Il server restituisce:
{
"access_token" : "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
"token_type" : "Bearer",
"expires_in" : 3600
}
e definire variabili oauth_token
, utilizzando:
data = simplejson.loads(result.content)
oauth_token = data['token_type'] + ' ' + data['access_token']
Considerando che potresti aver già controllato l'ID e il token di autenticazione, ti suggerisco di testare le tue query manualmente con [cURL] (http://en.wikipedia.org/wiki/CURL). A seconda del risultato, saprai se il problema è come costruisci il tuo URL, o qualcos'altro ... –
@AlexisHuet, Grazie per il suggerimento, ma comunque, sono sicuro che il problema non è nell'URL. Sicuramente, il problema è "qualcos'altro". – B7ackAnge7z
Hai provato con 'requests', per vedere se il problema è nel modulo che usi? –