我想使用gatsby-source-facebook显示文章 [英] I want to display articles using gatsby-source-facebook
问题描述
我想使用gatsby-source-facebook显示文章的数据. 但是我不知道如何编写查询. 我在 http://localhost:8000/___ graphql
I want to display the data of an article using gatsby-source-facebook. But I don't know how to write a query. I can't find the best query at http://localhost:8000/___graphql
我用gatsby.js
创建一个简单的网站.
我想获取Facebook文章数据(发布日期和文字)并显示在网站上.
我为此安装了gatsby-source-facebook
.
并更改为gatsby-config.js
.
→ https://www.gatsbyjs.org/packages/gatsby-source-facebook/
I make a simple website with gatsby.js
.
I want to get facebook article data (posting date and text) and display it on the site.
I installed gatsby-source-facebook
for that.
And changed gatsby-config.js
.
→ https://www.gatsbyjs.org/packages/gatsby-source-facebook/
//`gatsby-config.js`
plugins: [
{
resolve: `gatsby-source-facebook`,
options: {
places: [`${facebookPageID}`], // Can be either a numeric ID or the URL ID
params: {
fields: 'hours, posts { message, created_time }', // See Facebooks API to see what you can query for
},
key: process.env.FACEBOOK_GRAPH_TOKEN, // You will need to create a Facebook application and go through review in order to get an API token.
},
},
],
我不知道如何编写查询,所以我无法获取数据. (无法显示.) 例如, http://localhost:8000/___ graphql
I don't know how to write a query, so I can't get the data. (Can not be displayed.) For example, http://localhost:8000/___graphql
query {
site {
siteMetadata {
title
description
}
}
}
如果输入并执行},将显示在gatsby-config.js
输入代码中设置的站点的标题和描述.这是正常的.那么,如何编写查询以显示Facebook文章数据?
If you enter and execute}, the title and description of the site set in gatsby-config.js
enter code here will be displayed. This is normal. So how do you write a query to display facebook article data?
为了解决这个问题,我进行了很多搜索,但没有找到解决方案. 我只发现了一个类似的问题(如何在Gatsby中添加Facebook评论插件? ),但无法解决.这个问题与我在这里写的内容相同( https://www.gatsbyjs. org/packages/gatsby-source-facebook/).
I searched a lot to solve this problem, but I didn't find a solution. I only found a similar question (How to add facebook comment plugin in Gatsby?) but it could not be resolved. This question was the same as what I wrote here (https://www.gatsbyjs.org/packages/gatsby-source-facebook/).
推荐答案
tl; dr:
尝试一下:
tl;dr:
Try this:
query {
allFacebookArticles {
edges {
node {
title,
description
}
}
}
}
说明
该插件存储将其数据转换为与Facebook${type}
格式相匹配的类型,其中$type
是要提取的事物的类型(在您的情况下为文章,因此为FacebookArticle
).
Explanation
That plugin stores its data into types matching the format Facebook${type}
where $type
is the type of thing you're pulling (in your case, articles, so it'd be FacebookArticle
).
不过,从GraphiQL中,您应该能够在左侧的侧边栏中看到它.
From GraphiQL, though, you should be able to see that on the sidebar on the left.
这是我当前项目中的一个示例(打开了其他一些选项):
Here's an example from my current project (with some other options open):
这篇关于我想使用gatsby-source-facebook显示文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!