【发布时间】:2022-01-27 20:28:03
【问题描述】:
我正在使用这个 linkedin-private-api 连接到linkedin voyager api的库。
当我运行此代码时,我得到一个无效的 json 响应,如下所示:�/J�>�2:��������i�f{�|tV4���>X� �+��0
但是当我使用 Postman 时,我得到了一个有效的 json 响应
"data": {
"metadata": {
"type": "TypeaheadFindByType",
"id": "ff39d918-5e52-4a14-9aa3-6c37c72cb81b",
"$type": "com.linkedin.voyager.typeahead.TypeaheadMetadata"
},
"entityUrn": "urn:li:collectionResponse:IFrGi77656cS3A4SqIFwTMfpqxVjguPOPn6DHgNnpiQ=",
"elements": [
{
"targetUrn": "urn:li:fs_geo:103688978",
"text": {
"text": "Sousse Governorate, Tunisia",
"$type": "com.linkedin.pemberly.text.AttributedText"
},
"dashTargetUrn": "urn:li:fsd_geo:103688978",
"type": "GEO",
"trackingId": "JLoPDNEmRo2BEEQr26vinw==",
"$type": "com.linkedin.voyager.typeahead.TypeaheadHitV2"
}
}
这是完整的nodejs测试代码:
const {Client} = require('linkedin-private-api');
const https = require('https')
test();
async function test() {
const client = new Client();
await client.login.userPass({
username: "username",
password: "password"
});
var _headers = client.request.request.defaults.headers
const options = {
hostname: 'www.linkedin.com',
path: '/voyager/api/typeahead/hitsV2?keywords=USA&origin=OTHER&q=type&queryContext=List(geoVersion-%3E3,bingGeoSubTypeFilters-%3EMARKET_AREA%7CCOUNTRY_REGION%7CADMIN_DIVISION_1%7CCITY)&type=GEO',
method: 'GET',
headers: _headers
}
https.get(options, function (res) {
var json = '';
res.on('data', function (chunk) {
json += chunk;
});
res.on('end', function () {
if (res.statusCode === 200) {
try {
// data is available here:
console.log(json);
} catch (e) {
console.log('Error parsing JSON!');
}
} else {
console.log('Status:', res.statusCode);
}
});
}).on('error', function (err) {
console.log('Error:', err);
});
}
【问题讨论】:
-
感谢您的尝试,但这并没有解决问题我总是得到一个奇怪的字符。
标签: node.js postman linkedin-api