如何正确设置授权以使用 Nativescript[2.5.4] 使用 Wordpress Rest API (Oauth1)?

How to properly set Authorization to consume Wordpress Rest API (Oauth1) with Nativescript[2.5.4]?

我正在尝试使用 Nativescript 使用 WP Rest API。

  1. WP API 和 OAUTH1 的授权已经很好地设置并使用 POSTMAN 进行了测试。
  2. 使用 rest 的 Nativescript 登录功能也已设置,无需 OAUTH 即可工作。

现在我正在尝试使用 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);
   }

但是我得到一个错误,这个错误意味着 授权格式不正确或发送不正确 :

"data": {
    "code": "rest_cannot_access",
    "message": "Only authenticated users can access the REST API.",
    "data": {
        "status": 401
    }
}

如何在 Nativescript 中正确使用 oauth1?

我刚刚使用开源插件切换到 OAUTH2 :

https://github.com/wlcdesigns/WP-OAuth2-Server-Client

authorization : Bearer

一起使用更方便