gpt4 book ai didi

javascript - GatsbyJS 和 Wordpress REST API 401 未授权错误

转载 作者:行者123 更新时间:2023-12-01 17:30:29 25 4
gpt4 key购买 nike

我刚刚使用 GatsbyJS 试用了 Wordpress 的 REST API,但出现以下错误:

success onPreBootstrap — 0.005 s
⠠ source and transform nodes -> wordpress__POST fetched : 6
⠐ source and transform nodes -> wordpress__PAGE fetched : 2
⠈ source and transform nodes -> wordpress__wp_media fetched : 15
⠠ source and transform nodes -> wordpress__wp_types fetched : 1
⡀ source and transform nodes -> wordpress__wp_statuses fetched : 1
⠁ source and transform nodes -> wordpress__wp_taxonomies fetched : 1
⠠ source and transform nodes -> wordpress__CATEGORY fetched : 8
⢀ source and transform nodes -> wordpress__TAG fetched : 5
⠂ source and transform nodes -> wordpress__wp_users fetched : 2
⠐ source and transform nodesThe server response was "401 Unauthorized"
Inner exception message : "You are not currently logged in."
⢀ source and transform nodes -> wordpress__wp_comments fetched : 0
⡀ source and transform nodesThe server response was "401 Unauthorized"
Inner exception message : "Sorry, you are not allowed to do that."
success source and transform nodes — 16.447 s
success building schema — 0.339 s
success createLayouts — 0.015 s
success createPages — 0.004 s
success createPagesStatefully — 0.010 s
success onPreExtractQueries — 0.001 s
success update schema — 0.160 s
success extract queries from components — 0.088 s
success run graphql queries — 0.030 s
success write out page data — 0.003 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.001 s

到目前为止,我只通过 npm 安装了 gatsby-source-wordpress 并将我的 gatsby-config 更改为:

module.exports = {
siteMetadata: {
title: 'Gatsby Default Starter',
},
plugins: [
'gatsby-plugin-react-helmet',
/*
* Gatsby's data processing layer begins with “source”
* plugins. Here the site sources its data from Wordpress.
*/
{
resolve: `gatsby-source-wordpress`,
options: {
/*
* The base URL of the Wordpress site without the trailingslash and the protocol. This is required.
* Example : 'gatsbyjswpexample.wordpress.com' or 'www.example-site.com'
*/
baseUrl: `myurl.com`,
// The protocol. This can be http or https.
protocol: `http`,
// Indicates whether the site is hosted on wordpress.com.
// If false, then the asumption is made that the site is self hosted.
// If true, then the plugin will source its content on wordpress.com using the JSON REST API V2.
// If your site is hosted on wordpress.org, then set this to false.
hostingWPCOM: false,
// If useACF is true, then the source plugin will try to import the Wordpress ACF Plugin contents.
// This feature is untested for sites hosted on Wordpress.com
useACF: false,
},
},
],


};

最佳答案

以下是我如何摆脱 gatsby-source-wordpress 插件 ( click here for documentation on npm ) 中的 401 Unauthorized 警告。

警告:

Path: /wp-json/wp/v2/users/me?per_page=100&page=1
The server response was "401 Unauthorized"
Inner exception message: "You are not currently logged in."

使用 gatsby-config.js 中的 includedRoutes 设置只包含您需要的路由:

includedRoutes: [
"**/posts",
"**/pages",
"**/media",
"**/categories",
"**/tags",
"**/taxonomies",
// "**/users", // uncomment this and watch the warning above reappear!
"**/menus",
],

关于javascript - GatsbyJS 和 Wordpress REST API 401 未授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48406021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com