我正在尝试使用Nativescript来使用WP Rest API。
现在我正在尝试使用OAUTH登录代码:
authorizationString = 'OAuth oauth_consumer_key="T2yXcbN28Ufj",
oauth_token="AmEVr5oSNmbKyZKccFjtmnSk",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1492267438",
oauth_nonce="rGFJG2",
oauth_version="1.0",
oauth_signature="Ru%2BaSvsZn2liesd2ENy8GeNsdHY%3D"';
login(user: User){
console.log("Try to login User : " + user.email);
let headers = new Headers({"Authorization": authorizationString});
let body = JSON.stringify({
username: user.username,
email: user.email,
password: user.password
});
headers.append("Content-Type", this.contentType);
return this.http.post(
this.api,
body,
{headers: headers}
)
.map( response => response.json() )
.do(data => {
//Do work!!
})
.catch(this.handleErrors);
}
但是我收到了一个错误,这个错误意味着 autorization格式不正确或发送:
"data": {
"code": "rest_cannot_access",
"message": "Only authenticated users can access the REST API.",
"data": {
"status": 401
}
}
如何正确使用oauth1和Nativescript?
答案 0 :(得分:0)
我刚刚使用开源插件切换到OAUTH2:
https://github.com/wlcdesigns/WP-OAuth2-Server-Client
使用authorization : Bearer