all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to send a request to a Website.
@ 2017-04-20 10:59 Thierry Leurent
  2017-04-20 14:54 ` Eric Abrahamsen
  0 siblings, 1 reply; 7+ messages in thread
From: Thierry Leurent @ 2017-04-20 10:59 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Hello,
Hello,

I'm working on a way to post article to a WordPress blog using OAuth2.
I'm able to retrieve the OAuth2 token but I cannot publish a post using Emacs. 
I'm not allowed, why ???? I don't know but I can do it using Python so I would 
like understant what append.

Thank.

Thierry 


Emacs' Code ---------------
(require 'url)
(require 'url-http)
(require 'json)
(defvar user-data
  (with-current-buffer
      (progn
	(url-request-method        "POST")
	(url-request-extra-headers `(("Content-Type" . "application/x-www-form-
urlencoded")
				     ("Authorization" . "bearer 
1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt")))
	(url-request-data          (json-encode '(:title "Post using emacs.")))
	(url-retrieve-synchronously "https://asgardian.be/WordPress/wp-json/wp/v2/
posts?state=1234&access_token=1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt")
	)
    (goto-char url-http-end-of-headers)
    (json-read)
    ))
(message "DBG - Result : %s " user-data)

DBG - Result : ((code . rest_cannot_create) (message . Sorry, you are not 
allowed to create posts as this user.) (data (status . 401))) 

Python's code -------------------
import urllib
import httplib2
import pprint
http = httplib2.Http()
url = 'https://asgardian.be/WordPress/wp-json/wp/v2/posts?
state=1234&access_token=1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt'   
headers = {'Content-type': 'application/x-www-form-urlencoded', 
'Authorization': 'bearer 1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt'}
body = {"title":"New post using emacs and python"}
response, content = http.requestb(url, 'POST', headers=headers, 
body=urllib.urlencode(body))
print(" Content : {}" .format(content))

-- 
Thierry Leurent




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-04-20 21:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-20 10:59 How to send a request to a Website Thierry Leurent
2017-04-20 14:54 ` Eric Abrahamsen
2017-04-20 17:02   ` Thierry Leurent
2017-04-20 17:24     ` Eric Abrahamsen
2017-04-20 18:07       ` Thierry Leurent
2017-04-20 18:15       ` Kevin Buchs
2017-04-20 21:22         ` Thierry Leurent

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.