Home>
https://izm51.com/posts/nuxt-contentful-netlify-blog-making-1/
I tried to do Nuxt + Contentful CMS while watching, but I get an error with the access token.
{{post.fields.title}}
is not displayed. .
Console error display
index.vue
<template>
{{post.fields.title}}
</template>
<script>
import client from '~/plugins/contentful'
export default {
asyncData ({params}) {
return client
.getEntries ({
content_type: 'post',
order: '-sys.createdAt',
})
.then (entries =>{
return {posts: entries.items}
})
.catch (e =>console.log (e))
},
head: {
title: 'latest Posts',
},
methods: {
formatData (iso) {
const date = new Date (iso)
const yyyy = new String (data.getFullYear ())
const mm = new String (data.getMonth () + 1) .padStart (2, "0")
const dd = new String (date.getDate ()). padStart (2, "0")
return `${yyyy}. ${mm}. ${dd}`
}
},
// methods "posts" is not defined on the ~~
props: {
posts: {
type: String
}
}
}
</script>
nuxt.config.js
require ('dotenv'). config ()
const client = require ('./ plugins/contentful')
module.exports = {
head: {
title: 'nuxt-cms',
meta: [
{charset: 'utf-8'},
{name: 'viewport', content: 'width = device-width, initial-scale = 1'},
{hid: 'description', name: 'description', content: 'Nuxt.js project'}
],
link: [
{rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'}
]
},
loading: {color: '# 3B8070'},
build: {
extend (config, {isDev, isClient}) {
if (isDev&&isClient) {
config.module.rules.push ({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude:/(node_modules) /
})
}
}
},
plugins: [
'~/plugins/contentful'
],
modules: [
'@ nuxtjs/dotenv',
'@ nuxtjs/markdownit'
],
markdownit: {
injected: true,
html: true,
linkify: true,
typography: true,
},
generate: {
routes () {
return client
.getEntries ({content_type: 'post'})
.then (entries =>{
return entries.items.map (entry =>{
return {
route: "/posts/"+entry.fields.slug,
payload: entr
}
})
})
}
},
env: {
CTF_SPACE_ID: process.env.CTF_SPACE_ID,
CTF_CDA_ACCESS_TOKEN: process.env.CTF_CDA_ACCESS_TOKEN,
}
}
contentful.js
const contentful = require ("contentful")
const config = {
space: process.env.CTF_SPACE_ID,
accessToken: process.env.CTF_CDA_ACCESS_TOKEN
}
const client = contentful.createClient (config)
export default client
Because it is ↓ even if curl directly from the API key set in contentful (reference: https://www.contentful.com/developers/docs/references/authentication/) I don't understand well. . Congratulations><
# Request
curl https://cdn.contentful.com/spaces/cfexampleapi/entries?access_token=wrong
# Response
{
"sys": {
"type": "Error",
"id": "AccessTokenInvalid"
},
"message": "An access token is required. Please send one through the HTTP Authorization header or as the query parameter \" access_token \ ".",
"requestId": "Take me down"
}
-
Answer # 1
Related articles
- php - error when getting access token with line api
- i want to know why an access error occurs when creating a vbo buffer in opengl
- api - error when curl firebase functions http request url
- php - cannot get access token
- curl - cannot get access token with instagram basic display api
- python - [error 5] access is denied: occurs in osmakedirs
- ruby - access denied error when deploying capistrano
- javascript - i want to solve the unexpected token error to async "(") in nodejs
- api - 400 batrequest error does not recover
- cors error occurs when hitting api
- arduino error code before'(' token resolution
- 401 error occurs when loading api
- about access error
- linux - in vscode, i don't know how to resolve error: 5 access denied
- same source error occurs when hitting twitter api from client side with fetch
- mysql - access denied for user error in xserver
- is authentication using an access token secure with swift + cakephp?
- c ++ - mbstowcs_s ();i want to know the cause of an access error in a function
- c # - xauth to get access token of cybozu live api is moss
- google api - i want to resolve google authentication error 403: access_denied
Related questions
- ruby on rails - rails (devise_token_auth) × nuxtjs (auth module) there is no necessary information in the response header when a
- How can I determine the ip of a user in Laravel + Nuxt?
- javascript : I want to replace it with a substitute image when a 404 error occurs when loading an image in Nuxt.js
- the screen is not displayed due to the bundled settings of spring and nuxtjs
- javascript - should rails apps split the front end?
- php - i want to pass a column name string in nuxtjs vuejs and refer to a variable
- javascript - how to have a fixed value in saas with different domains
- how to convert javascript to typescript in vuejs
- javascript - i want to hide the information displayed in the select box when it is selected
- i want to create a development environment where nodejs, vuejs, nuxtjs coexist with docker
How to use contentful.createClient () itself is the same.
You can't get it even with curl, so I think access_token is wrong as pointed out in the error statement.
Please check if you can specify "Content Delivery API-access token" correctly.
Possibly not relevant, but if you have multiple environments in Contentful, you may need to set environment (this is unconfirmed).