标签: contentful

Contentful API 在条目更新时返回“版本不匹配”

我尝试使用 Contentful 的内容管理 API 执行以下操作:

  1. 获取条目(条目1)
  2. 使用条目 1 中字段的数据查找另一个条目 (条目 2)
  3. 使用条目 2 中的数据更新条目 1

我的代码如下所示:

client.getSpace("xxxxxxxx").then(function(space){
  space.getEntries({
    "content_type": "xxxxxxxx",
    "sys.id": "2KEZYJOgDSeQMCQIE0Oo88",
    "limit": 1
  }).then(function(places){

    //search for relevant category entry
    space.getEntries({
      "content_type": contentType.category,
      "sys.id": places[0].fields.category["en-GB"],
      "limit": 1
    }).then(function(category){

      //update place object
      places[0].fields.categoryNew = {
        "en-GB": [ 
          { sys: { type: "Link", linkType: "Entry", id: category[0].sys.id } } 
        ]
      };        

      //update place
      request({
        method: 'PUT',
        url: 'https://api.contentful.com/spaces/xxxxxxxx/entries/' + places[0].sys.id,
        headers: {
          'Authorization': 'Bearer xxxxxxxx',
          'Content-Type': 'application/vnd.contentful.management.v1+json',
          'X-Contentful-Content-Type': 'xxxxxxxx'
        },
        body: JSON.stringify({fields:places[0].fields}) …
Run Code Online (Sandbox Code Playgroud)

javascript api json node.js contentful

4
推荐指数
1
解决办法
3661
查看次数

解析express应用程序中的url哈希片段

我正在编写一个快速应用程序,我必须使用 oauth 2.0 流程对用户进行身份验证。我已成功将用户重定向到 oauth 提供程序,并且提供程序在 oauth 回调中发送访问令牌。就像是

http://localhost:4000/oauth/callback#access_token=<token>
Run Code Online (Sandbox Code Playgroud)

现在我有一个快速路线处理程序,例如

app.get('/oauth/callback', function(req, res, next) {
});
Run Code Online (Sandbox Code Playgroud)

我知道哈希片段不会传递到服务器,但这是一个 oauth 回调。

如何在路由处理程序中获取 url 哈希片段?

javascript oauth node.js express contentful

4
推荐指数
1
解决办法
4969
查看次数

TypeError:将循环结构转换为 JSON - 在 json 中查找错误

我正在使用 Contentful 和 MEAN 堆栈。我查询 Contentful API 并返回一个 json 对象。

contentClient.entries(query, function(err, entries){
  if (err) throw err;
  console.log(entries);
});
Run Code Online (Sandbox Code Playgroud)

我刚刚收到以下错误:

[TypeError: Converting circular structure to JSON]

该对象很大(当我将其从控制台导出到文档时,超过 3000 行)。所以我不能在这里发布它,但我想知道是否有办法找到对象内循环结构问题的位置以及如何解决这个问题?

javascript json node.js contentful

3
推荐指数
1
解决办法
5321
查看次数

更新内容条目

我在尝试使用 Javascript 中的典型 http 请求更新 Contentful 条目时遇到了困难;我收到错误代码“VersionMismatch”,根据文档,这意味着:

当您尝试更新现有资产、条目或内容类型,并且未指定对象的当前版本或指定过时的版本时,会出现此错误。

但是,我已根据文档使用“X-Contentful-Version”标头参数指定了条目的当前版本,并使用“entry.sys.revision”中的动态属性值作为参数值(以及对当前版本进行硬编码,加上一堆不同的数字,但我总是收到相同的错误)。这篇文章报告了完全相同的问题,但似乎通过添加此标头参数解决了。

这是我当前的代码,它也使用 Contentful API 从我的 Contentful 空间检索条目,但由于特定要求,我必须使用纯 Javascript 来将数据放回:

var client = contentful.createClient(
    {
        space: space_id,
        accessToken: client_token
    }
);

client.getEntry(entry_id).then((entry) => entry).then(function(entry) {

    // update values of entry
    entry.fields.title = "Testing";

    // post data to contentful API
    var request = new XMLHttpRequest();
        request.open('PUT', 'https://api.contentful.com/spaces/' + space_id + '/entries/' + entry_id);
        request.setRequestHeader('Authorization', 'Bearer my_access_token');
        request.setRequestHeader('Content-Type', 'application/vnd.contentful.management.v1+json');
        request.setRequestHeader('X-Contentful-Content-Type', entry.sys.contentType.sys.id);

        // setting the 'X-Contentful-Version' header with current/soon to be old version
        request.setRequestHeader('X-Contentful-Version', …
Run Code Online (Sandbox Code Playgroud)

contentful contentful-management

3
推荐指数
1
解决办法
9128
查看次数

逗号出现在 Javascript 呈现的 HTML 中

我正在使用 Javascript 和 Contentful 呈现 HTML。

我的代码:

contentfulClient.getEntries({
   content_type: PRODUCT_CONTENT_TYPE_ID,
   order: '-fields.dateRated'
})
.then(function(entries) {
   container.innerHTML = renderProducts(entries.items)
})

function renderProducts(products) {
   return '<table id="film-table"><tr><th>Name</th><th>Rating</th></tr><tr><td>Check back tomorrow</td><td class="rating-cell"></td></tr>' +
   products.map(renderSingleProduct) +
   '</table>'
}
Run Code Online (Sandbox Code Playgroud)

但是,当我对此进行测试时,每个条目的表格上方都会出现一个逗号: 逗号上方的表格

谢谢您的帮助。

html javascript contentful

3
推荐指数
1
解决办法
520
查看次数

是否有一个 html 到富文本 npm 包用于内容丰富

我正在尝试将内容从一个系统(具体来说是 Drupal)迁移到 Contentful 中。

当从 Drupal 中提取内容时,它会被格式化为 HTML。将内容放入Contentful中,看起来需要采用特定的JSON格式。

contentful-cli通过命令使用 NPM 包contentful space import --content-file import.json

我知道有@contentful/rich-text-html-render,但我正在寻找相反的情况。或者,如果有另一种策略,任何人都知道以编程方式将 html 导入到 Contentful 中......

node.js npm contentful

3
推荐指数
1
解决办法
2508
查看次数

以 Angular 显示 ContentFul RichText

我的 Angular 应用中有一个与 Contentful 相关的博客提要。感谢 Contentful javascript sdk。

https://www.contentful.com/developers/docs/javascript/tutorials/using-contentful-in-an-angular-project/

我正在尝试显示标题和文本字段。这是我的代码:

import { Component, OnInit } from '@angular/core';
import {Observable} from 'rxjs';
import {ContentfulService} from '../../services/contentful/contentful.service';
import { Entry } from 'contentful';

@Component({
  selector: 'app-blog',
  templateUrl: './blog.component.html',
  styleUrls: ['./blog.component.scss']
})
export class BlogComponent implements OnInit {
  private posts: Entry<any>[] = [];

  constructor(private postService: ContentfulService) {}

  ngOnInit() {
    this.postService.getPosts()
      .then(posts => {
        this.posts = posts;
        console.log(this.posts);
      });
  }
}
Run Code Online (Sandbox Code Playgroud)

和 html:

<div *ngFor="let post of posts">
    <a href="#">{{ post.fields.title }}</a>
    <div>{{ post.fields.text …
Run Code Online (Sandbox Code Playgroud)

javascript typescript contentful angular

3
推荐指数
1
解决办法
2553
查看次数

使用 Contentfuls 富文本反应渲染创建摘录

我正在研究如何使用 Contentful Rich Text React Renderer 将摘录引入我的网站。

我有点挣扎,这是我第一次使用它。我过去曾使用过MD,内容丰富,但由于用户的原因,我需要丰富的测试。

这是我的查询。

export const query = graphql`
    query($slug: String!) {
        contentfulJobListings(slug: { eq: $slug }) {
            jobTitle
            jobPostedDate(formatString: "MMMM Do, YYYY")
            jobSalaryN
            jobLocation
            jobDescription {
                json
            }
        }

    }
`
Run Code Online (Sandbox Code Playgroud)

这就是我在页面上生成富文本的方式<div>{documentToReactComponents(props.data.contentfulJobListings.jobDescription.json)}</div>

在进入正文之前,我想摘录一段内容来解释一下。

如果有人能帮忙解决这个问题那就太好了。因为我闲着。

reactjs contentful graphql gatsby

3
推荐指数
1
解决办法
1634
查看次数

Contentful GraphQL 端点:如何检索内容类型的所有条目

{
  Post {
      name
  }
}
Run Code Online (Sandbox Code Playgroud)

在尝试检索内容类型上的所有条目时,它仅给出以下错误:

"Argument \"id\" of required type \"String!\" was not provided."
Run Code Online (Sandbox Code Playgroud)

由于id需要字段。那么如何获取某个内容类型的所有条目呢?

参考:https: //www.contentful.com/developers/docs/references/graphql/

contentful graphql

3
推荐指数
1
解决办法
5900
查看次数

Contentful:如何更改条目名称?

我正在尝试使用 Contentful Web 界面来更改条目的名称。附上一张截图。我已经搜索了 30 分钟才能找到可以将标题从“无标题”更改为其他内容的按钮。唉,在这个可怕的、可怕的界面上找不到它。

它在哪里?它真的存在吗?

contentful

3
推荐指数
1
解决办法
1609
查看次数