MuYunyun/flow

掘金的api换了

TendernessCJS opened this issue · 3 comments

掘金的接口换成 web-api.juejin.im/search 了,post请求。。。

const options = {
    /* 省略 */
    'juejin': {
       hostname: 'web-api.juejin.im',
       method: 'post',
       path: '/query',
       headers: {
      'Content-Type': 'application/json',
      'X-Agent': 'Juejin/Web',
    },
  },
}[item]

function getJueJin(handleDataFn) {
  const req = https.request(options, (res) => {
    res.setEncoding('utf8');
    res.on('data', (chunk) => {
      content += chunk;
    }).on('end', () => {
      const jsonContent = JSON.parse(content);
      handleDataFn(jsonContent);
    });
  });
  req.write(JSON.stringify({
    extensions: {
      query: { id: 'a53db5867466eddc50d16a38cfeb0890' },
    },
    operationName: '',
    query: '',
    variables: {
      after: '',
      first: 100,
      period: 'ALL',
      query: keyword,
      type: 'ARTICLE',
      order: 'POPULAR',
    },
  }));
  req.end();
}

// 对应的掘金结果
getJueJin((jsonContent) => {
    const result = jsonContent.data.search.edges;
    for (let i = 0; i < result.length; i++) {
      const item = result[i].node.entity;
      const author = item.user;
      result_array.push({
        title: item.title,
        subtitle: `点赞数${item.collectionCount} 作者: ${author.username}${author.jobTitle ? `(${author.jobTitle})` : ''}`,
        arg: item.originalUrl,
        icon: {
          path: join(__dirname, '/17C80585-EC4F-498F-AB91-DBA6EBEA4C9D.png'),
        },
        mods: {
          cmd: {
            arg: item.originalUrl,
            subtitle: item.content,
          },
        },
      });
    }
    showItem(result_array);
});

欢迎 pr

image

貌似掘金的 api 又换了。你提供的也失效了。

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.