I hope to know the cloud"s open api, with python requests operation, but always fail, asking the big god to solve the problem.
this is their js example:
https://doc.minapp.com/open-a.
var request = require("request");
// code
var opt = {
uri: "https://cloud.minapp.com/api/oauth2/hydrogen/openapi/authorize/",
method: "POST",
json: {
client_id: "a4d2d62965ddb57fa4xx",
client_secret: "e5802b40135baab9b4e84e35bed058a264c37dxx"
},
jar: true, // cookie
followAllRedirects: true, //
}
request(opt, function(err, res, body) {
getToken(body.code) // getToken
})
// token
function getToken(code) {
var opt = {
uri: "https://cloud.minapp.com/api/oauth2/access_token/",
method: "POST",
formData: { // data "Content-Type": "multipart/form-data"
client_id: "a4d2d62965ddb57fa4xx",
client_secret: "e5802b40135baab9b4e84e35bed058a264c37dxx",
grant_type: "authorization_code",
code,
}
}
request(opt, function(err, res, body) {
let token = JSON.parse(body).access_token
})
}
this is my python code:
import requests
import json
client_id = ""
client_secret = ""
r = requests.post("https://cloud.minapp.com/api/oauth2/hydrogen/openapi/authorize/", json={"client_id": client_id, "client_secret": client_secret})
code = json.loads(r.content)["code"]
print code
-sharpcode
headers = {"Content-Type": "multipart/form-data"}
payload = {"client_id":client_id,"client_secret":client_secret, "grant_type" : "authorization_code", "code" : code}
r = requests.post("https://cloud.minapp.com/api/oauth2/access_token/", headers=headers, data=payload)
print r.content
I don"t know why 400 is always returned