获取最近写过的Matters文章就和点奶茶一样简单
API的作用其实和奶茶店店员一样,你到柜台点奶茶,店员就去后台把你要求的东西(奶和。。。茶?)放在一起拿回来给你。今天我们来试试用Matters的奶茶店店员点写过的文章。
《社區開放一小步:Matters API》里说我们可以在https://server.matters.news/playground使用API,playground顾名思义就是可以直接玩耍的意思,有时候我们也会把这种不用自己搭建环境的界面称为sandbox,可以堆沙堡但是真的买了一个放在院子里路边的野猫们会把它当公厕然后下一次你去玩沙就会。。。嗯就是那个sandbox(勾起了什么不好的回忆)。

看来程序员都有未泯的童心呢(轻轻拭泪)。
好的,把https://server.matters.news/playground贴到浏览器搜索栏,你会看到以下画面:

我知道!都是黑色!不要怕!让我们来看看这黑黑的界面都有什么。
【1】https://server.matters.news/graphql是endpoint,其实就是奶茶店柜台,你要到这里点才点得到奶茶。
【2】是我们点餐的地方。
【3】是取餐区。
【4】这个文档是我们的菜单。
我们来看看菜单上有什么。

你会看到Queries和Mutations两个分类,不需要以作者身份操作的事都分在Queries,获取某个人发布过的文章就属于Queries的一种。

点user后会弹出副菜单,往下刷会看到Arguments,它是奶茶的价格。这里我们知道要点user就得付userName,userName就是你的用户名。

往上滑会看到Type Details,店员问你加不加珍珠,你说加店员又问你要大中还是小颗,你想了三十二分之一天后终于决定要大颗的,店员又问你珍珠的形状有星星型的你要不要。

最后你终于完成了你的点餐,你点了作者(user)的所有文章(articles)分类下能看到的(edges)所有文章(node)。
我们先把这些写进点餐区。

好,让我们把刚刚的一口气依序吐出来,query分类下的user的articles的edges的node,然后别忘了点user要付userName(点articles的可以空着)。
哈~
现在到了最关键的时刻,加不加糖!
开玩笑,反正点多少感觉店员都没听,关键的是每篇文章我们想要获取什么资料。
我们的选项有作者啦、标题啦、内容啊、评论啊等等。我们就点个标题、日期和字数吧。

填好后点击中间那个play button。

点。

取餐区就会看到我们的奶茶啦!userName就是作者个人主页下方那个@什么的什么。你可以看到我发的文从100到1000字不等。
好吧,其实点奶茶没有想象中那么简单,我还是喝果汁好了。
Like my work? Don't forget to support and clap, let me know that you are with me on the road of creation. Keep this enthusiasm together!


