【问题标题】:Setup Contentful Javascript SDK in React Native在 React Native 中设置 Contentful Javascript SDK
【发布时间】:2020-11-23 17:46:05
【问题描述】:

我正在尝试在 React Native 项目(没有 Expo)上实现 Contentful Javascript SDK。

这是代码:

const {createClient} = require('contentful/dist/contentful.browser.min.js')

useEffect(() => {
    getContentfulData()
}, [])

const getContentfulData = async () => {
    var client = createClient({
    adapter: (config) => {
        config.adapter = null
        return fetch(config)
    },
    space: '---',
    accessToken: '---',
    })

    await client
        .getEntries()
        .then((entries) => {
            console.log(entries)
        })
        .catch((error) => {
            console.log(error)
        })
}

但我一遍又一遍地收到 TypeError: Network request failed

有什么想法吗?

【问题讨论】:

    标签: reactjs react-native contentful contentful-vault


    【解决方案1】:
    const { createClient } = require('contentful/dist/contentful.browser.min.js')
    
      const client = createClient({
        space: '*********',
        accessToken: '****************************************',
      })
    
        client
          .getEntries({
            content_type: 'trendingBlogs',
          })
          .then(entry => console.log(entry))
          .catch(err => console.log(err))
    
    

    您缺少 getEntries 参数。 即

    {
      content_type: 'trendingBlogs',
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-11
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多