javascript 无法为bible API设置带有axios的标头

wlsrxk51  于 2023-01-01  发布在  Java
关注(0)|答案(2)|浏览(94)

下面是我的代码:

import axios from 'axios';

const API = axios.create({ baseURL: 'https://api.scripture.api.bible' });

API.defaults.headers.common['api-key'] = 'MY_API_KEY';
API.defaults.headers.get['content-type'] = 'text';
API.defaults.headers.get['include-titles'] = false;
API.defaults.headers.get['include-verse-numbers'] = false;

export const getEnglishVerse = (verseId) => API.get(`/v1/bibles/65eec8e0b60e656b-01/verses/${verseId}`);
export const getItalianVerse = (verseId) => API.get(`/v1/bibles/41f25b97f468e10b-01/verses/${verseId}`);

The problem is that the last three headers don't work. There is the documentation: https://scripture.api.bible/livedocs#/Verses/getVerse
下面是我想要设置的:

在 Swagger 中一切都是好的,但我回应json的内容是这样的:

<p class="p"><span data-number="16" data-sid="JHN 3:16" class="v">16</span>Perciocchè Iddio ha tanto amato il mondo, ch'egli ha dato il suo unigenito Figliuolo, acciocchè chiunque crede in lui non perisca, ma abbia vita eterna. </p>

我只想在文本中的诗句,而不是在html(默认设置),但我的三个最后的标题,我试图设置错误。
你知道怎么做吗?

3qpi33ja

3qpi33ja1#

content-type应该放在查询字符串中:...?内容类型=文本...

nkhmeac6

nkhmeac62#

你可以得到圣经这段代码content-type是文本仍然是测试版。它返回JSON即使设置文本。

const axios = require('axios')
const getBible = async (bibleId, verseId) => {
    try {
        const resp = await axios.get(
            `https://api.scripture.api.bible/v1/bibles/${bibleId}/verses/${verseId}`,
            {
                params: {
                    'content-type': 'text',
                    'include-notes': false,
                    'include-titles': false,
                    'include-chapter-numbers': false,
                    'include-verse-numbers': true,
                    'include-verse-spans': false,
                    'use-org-id': false
                },
                headers: {
                    'Accept-Encoding': 'application/json',
                    'api-key' : '************ your api key *********'
                }
            }
        );
        return Promise.resolve(resp.data);
    } catch (err) {
        return Promise.reject(err);
    }
};

const EnglishVerse ='65eec8e0b60e656b-01'
const ItalianVerse ='41f25b97f468e10b-01'

getBible(EnglishVerse,'JHN.3.16')
    .then((result) => {
        console.log(result);
        console.log('English: ' + result.data.content);
    })
    .catch(error => console.log(error));
    
getBible(ItalianVerse,'JHN.3.16')
    .then((result) => {
        console.log(result);
        console.log('Italian: ' + result.data.content);
    })
    .catch(error => console.log(error));

结果

$ node get-bible.js
{
  data: {
    id: 'JHN.3.16',
    orgId: 'JHN.3.16',
    bookId: 'JHN',
    chapterId: 'JHN.3',
    bibleId: '65eec8e0b60e656b-01',
    reference: 'John 3:16',
    content: "     [16] For God loved the world, and this is how: he gave his one and only Son, so that everyone who trusts in him shouldn't die, but have eternal life. \n",
    verseCount: 1,
    copyright: 'Dr. Jonathan Gallagher. Released under Creative Commons Attribution-ShareAlike 4.0 Unported License. Version 4.1. For corrections send email to jonathangallagherfb
v@gmail.com',
    next: { id: 'JHN.3.17', number: '17' },
    previous: { id: 'JHN.3.15', number: '15' }
  },
  meta: {
    fums: '<script>\n' +
      'var _BAPI=_BAPI||{};\n' +
      "if(typeof(_BAPI.t)==='undefined'){\n" +
      `document.write('\\x3Cscript src="'+document.location.protocol+'//cdn.scripture.api.bible/fums/fumsv2.min.js"\\x3E\\x3C/script\\x3E');}\n` +
      `document.write("\\x3Cscript\\x3E_BAPI.t('b588e0e1-b3a1-4895-91bf-ab57e7feb91c');\\x3C/script\\x3E");\n` +
      `</script><noscript><img src="https://d3a2okcloueqyx.cloudfront.net/nf1?t='b588e0e1-b3a1-4895-91bf-ab57e7feb91c'" height="1" width="1" border="0" alt="" style="height: 0; wi
dth: 0;" /></noscript>`,
    fumsId: 'b588e0e1-b3a1-4895-91bf-ab57e7feb91c',
    fumsJsInclude: 'cdn.scripture.api.bible/fums/fumsv2.min.js',
    fumsJs: "var _BAPI=_BAPI||{};if(typeof(_BAPI.t)!='undefined'){ _BAPI.t('b588e0e1-b3a1-4895-91bf-ab57e7feb91c'); }",
    fumsNoScript: '<img src="https://d3btgtzu3ctdwx.cloudfront.net/nf1?t=b588e0e1-b3a1-4895-91bf-ab57e7feb91c" height="1" width="1" border="0" alt="" style="height: 0; width: 0;"
/>'
  }
}
English:      [16] For God loved the world, and this is how: he gave his one and only Son, so that everyone who trusts in him shouldn't die, but have eternal life.

{
  data: {
    id: 'JHN.3.16',
    orgId: 'JHN.3.16',
    bookId: 'JHN',
    chapterId: 'JHN.3',
    bibleId: '41f25b97f468e10b-01',
    reference: 'EVANGELO DI S. GIOVANNI 3:16',
    content: "     [16] Perciocchè Iddio ha tanto amato il mondo, ch'egli ha dato il suo unigenito Figliuolo, acciocchè chiunque crede in lui non perisca, ma abbia vita eterna. \n
",
    verseCount: 1,
    copyright: 'Public domain',
    next: { id: 'JHN.3.17', number: '17' },
    previous: { id: 'JHN.3.15', number: '15' }
  },
  meta: {
    fums: '<script>\n' +
      'var _BAPI=_BAPI||{};\n' +
      "if(typeof(_BAPI.t)==='undefined'){\n" +
      `document.write('\\x3Cscript src="'+document.location.protocol+'//cdn.scripture.api.bible/fums/fumsv2.min.js"\\x3E\\x3C/script\\x3E');}\n` +
      `document.write("\\x3Cscript\\x3E_BAPI.t('350cce2a-a308-43cd-9073-2bd8b87eef4d');\\x3C/script\\x3E");\n` +
      `</script><noscript><img src="https://d3a2okcloueqyx.cloudfront.net/nf1?t='350cce2a-a308-43cd-9073-2bd8b87eef4d'" height="1" width="1" border="0" alt="" style="height: 0; wi
dth: 0;" /></noscript>`,
    fumsId: '350cce2a-a308-43cd-9073-2bd8b87eef4d',
    fumsJsInclude: 'cdn.scripture.api.bible/fums/fumsv2.min.js',
    fumsJs: "var _BAPI=_BAPI||{};if(typeof(_BAPI.t)!='undefined'){ _BAPI.t('350cce2a-a308-43cd-9073-2bd8b87eef4d'); }",
    fumsNoScript: '<img src="https://d3btgtzu3ctdwx.cloudfront.net/nf1?t=350cce2a-a308-43cd-9073-2bd8b87eef4d" height="1" width="1" border="0" alt="" style="height: 0; width: 0;"
/>'
  }
}
Italian:      [16] Perciocchè Iddio ha tanto amato il mondo, ch'egli ha dato il suo unigenito Figliuolo, acciocchè chiunque crede in lui non perisca, ma abbia vita eterna.

curl命令可获取所有圣经ID列表
一个二个一个一个

相关问题