wordpress - React Native App with WordPress REST API - 不允许以该用户的身份创建帖子
问题描述
我正在使用 REST API 使用简单的Wordpress 后端在React Native中开发一个应用程序,在使用方法之前我没有任何问题。GET
现在我需要使用该POST
方法创建一篇博客文章,但仍然出现错误...
我有的:
- 带有激活的基本身份验证处理程序插件的 Wordpress -> https://github.com/WP-API/Basic-Auth
- 使用 WPAPI 客户端反应本机项目 - > https://github.com/WP-API/node-wpapi
我的反应代码:
const WPAPI = require( 'wpapi' );
let apiPromise = WPAPI.discover( 'https://myweb.com/wp-json' ).then(function( site ) {
return site.auth({
username: 'admin',
password: 'password'
});
});
apiPromise.then(function( site ) {
site.posts().create({
title: 'Your Post Title',
content: 'Your post content',
status: 'publish'
}).then(function( response ) {
console.log( response );
})
.catch(function(err){
console.log(err);
});
})
并总是得到这个答案:
"code": "rest_cannot_create",
"status": 401,
"message": "Sorry, you are not allowed to create posts as this user."
解决方案
推荐阅读
- reactjs - React Hook UseEffect 结合 Firebase 创建无限循环
- r - 如何将 dplyr summarise_all 结构内的 1 个函数中的多个值导出到结果表中的列
- android - 如何在 exo 播放器的媒体源列表中设置特定索引?
- node.js - 在 Angular 5 中创建构建时出错
- python - “selenium webdriverwait class”语法错误这段代码有什么问题吗?
- proxy - 如何使用 alfresco“配置 SSL”在 debian 中配置代理
- sql-server - 需要在 SQL Server 中动态更改视图中的 Databasename
- laravel - laravel:控制器已经存在
- wordpress - 向单个 CPT 页面添加分类术语会从常规页面中删除正文类
- android - 如何在android TextView中获取单击范围的x,y位置?