【发布时间】:2014-03-07 09:31:03
【问题描述】:
我已经在yotpo api中实现了以下帖子(足够简单的帖子请求)
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://yotpoapi.apiary.io/oauth/token');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (this.readyState == 4) {
if (typeof cb !== "undefined") {
cb(this);
}
else {
alert(this.responseText);
}
}
};
xhr.send("{\n \"client_id\": \"CLIENT ID\",\n \"client_secret\": \"CLIENT SECRET KEY\",\n \"grant_type\": \"client_credentials\"\n}");
响应如下(JSON格式)
{
"access_token": "DUGKea0thVDL2muWzMAd7mYlkni46cJWhiX9tGTF"
"token_type": "bearer"
}
我怎样才能摆脱除访问令牌响应之外的所有内容,以便它为我提供以下信息:DUGKea0thVDL2muWzMAd7mYlkni46cJWhiX9tGTF 在变量中。
抱歉,我以警报格式发布响应,因为我想实时查看它是什么。
【问题讨论】: