我正在尝试建立媒体集成,所以当我的新帖子到达媒体时,机器人会将帖子链接发送到不和谐频道。问题是我不知道如何从提要响应中获取数据,因此我可以在消息中使用它。一旦我收到来自提要的响应,它看起来像这样。
title: 'Hopefully will be done soon',
description: '<p>Still making final testing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d067e89b091" width="1" height="1" alt="">',
summary: null,
date: 2021-09-12T01:26:33.000Z,
pubdate: 2021-09-12T01:26:33.000Z,
pubDate: 2021-09-12T01:26:33.000Z,
link: 'https://rasmont.medium.com/hopefully-will-be-done-soon-3d067e89b091?source=rss-762047c9bd39------2',
guid: 'https://medium.com/p/3d067e89b091',
author: 'RasmonT',
comments: null,
origlink: null,
image: {},
source: {},
categories: [],
enclosures: [],
'rss:@': {},
'rss:title': { '@': {}, '#': 'Hopefully will be done soon' },
'rss:link': {
'@': {},
'#': 'https://rasmont.medium.com/hopefully-will-be-done-soon-3d067e89b091?source=rss-762047c9bd39------2'
},
'rss:guid': { '@': [Object], '#': 'https://medium.com/p/3d067e89b091' },
'dc:creator': { '@': {}, '#': 'RasmonT' },
'rss:pubdate': { '@': {}, '#': 'Sun, 12 Sep 2021 01:26:33 GMT' },
'atom:updated': { '@': {}, '#': '2021-09-12T01:26:33.080Z' },
'content:encoded': {
'@': {},
'#': '<p>Still making final testing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d067e89b091" width="1" height="1" alt="">'
},
meta: {
'#ns': [Array],
'@': [Array],
'#xml': [Object],
'#type': 'rss',
'#version': '2.0',
title: 'Stories by RasmonT on Medium',
description: 'Stories by RasmonT on Medium',
date: 2021-09-12T01:39:23.000Z,
pubdate: 2021-09-12T01:39:23.000Z,
pubDate: 2021-09-12T01:39:23.000Z,
link: 'https://medium.com/@rasmont?source=rss-762047c9bd39------2',
xmlurl: 'https://medium.com/@rasmont/feed',
xmlUrl: 'https://medium.com/@rasmont/feed',
author: 'yourfriends@medium.com',
language: null,
favicon: null,
copyright: null,
generator: 'Medium',
cloud: [Object],
image: [Object],
categories: [],
'rss:@': {},
'rss:title': [Object],
'rss:description': [Object],
'rss:link': [Object],
'rss:image': [Object],
'rss:generator': [Object],
'rss:lastbuilddate': [Object],
'atom:link': [Array],
'rss:webmaster': [Object]
}
},
我试图解析响应,所以我可以像这样从响应中获取链接。
const link = JSON.parse(entry) console.log('FEED Call response:', link["link"]);
client.on('ready', () => {
watcher.on('new entries', function (entries) {
entries.forEach(function (entry) {
const link = JSON.parse(entry)
console.log('FEED Call response:', link["link"]);
console.log(entry)
})
})
watcher
.start()
.then(function (entries) {
console.log(entries)
})
.catch(function(error) {
console.error(error)
})
})
知道如何从响应中接收我想要的数据,以便在消息中使用它吗?
错误:SyntaxError: Unexpected token o in JSON at position 1
更新:我尝试使用它,但是我不知道如何从响应中获取链接。
const link = JSON.stringify(entries)
console.log('FEED Call response:', link);
console.log(`Link:`, link[0].link)
响应是Link: [Function: link]