davideviolante / socialblade-com-api Goto Github PK
View Code? Open in Web Editor NEWUnofficial APIs for socialblade.com website.
License: MIT License
Unofficial APIs for socialblade.com website.
License: MIT License
It seems that the URL generated for YouTube does not provide the 30D period for the table, but only the 14D-ish period.
The reason is that the URL is generated us as follows:
function generateUrl(source, username) {
const userUrlCriteria = {
facebook: 'page',
youtube: 'channel',
};
const userUrl = userUrlCriteria[source] || 'user';
const urlSuffix = source === 'facebook' ? '' : '/monthly';
return `https://socialblade.com/${source}/${userUrl}/${username}${urlSuffix}`;
}
I think Social Blade updated their URL and now if you pass the 'channel' inside the URL it will redirect you to the user summary page and not the detailed statistics one.
The solution here is to pass the new URL with only 'c' as follows:
function generateUrl(source, username) {
const userUrlCriteria = {
facebook: 'page',
youtube: 'c',
};
const userUrl = userUrlCriteria[source] || 'user';
const urlSuffix = source === 'facebook' ? '' : '/monthly';
return `https://socialblade.com/${source}/${userUrl}/${username}${urlSuffix}`;
}
This way the page access is: https:// socialblade .com/youtube/c/{username}/monthly
Instagram return an empty table and value:
{ table: [], charts: [] }
I get an error when trying to hit certain profiles on Twitter such as bilaraujjo. The same error doesn't occur when hitting other profiles such as obama's.
The problem seems to happen for smaller profiles. My profile also returns an error.
Import the lib such as the example in readme file. Change Barack Obama profile for the ones mentioned above.
console.log (await socialblade(http://api.scraperapi.com?api_key=f941895b4d245ae8491266fe2f58bfef&url=<my_key>, 'twitter', 'bilaraujjo'))
TypeError: Cannot read property 'map' of null
at /Users/veller/Programming/seguidometro_bbb/node_modules/socialblade-com-api/functions.js:101:25
at Array.map (<anonymous>)
at convertArrayToObject (/Users/veller/Programming/seguidometro_bbb/node_modules/socialblade-com-api/functions.js:67:17)
at socialblade (/Users/veller/Programming/seguidometro_bbb/node_modules/socialblade-com-api/index.js:35:34)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async main (/Users/veller/Programming/seguidometro_bbb/socialblade.js:110:22)
Failed once, retrying...
TypeError: Cannot read property 'map' of null
at /Users/veller/Programming/seguidometro_bbb/node_modules/socialblade-com-api/functions.js:101:25
at Array.map (<anonymous>)
at convertArrayToObject (/Users/veller/Programming/seguidometro_bbb/node_modules/socialblade-com-api/functions.js:67:17)
at socialblade (/Users/veller/Programming/seguidometro_bbb/node_modules/socialblade-com-api/index.js:35:34)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async main (/Users/veller/Programming/seguidometro_bbb/socialblade.js:110:22)
Failed once, retrying...
TypeError: Cannot read property 'map' of null
at /Users/veller/Programming/seguidometro_bbb/node_modules/socialblade-com-api/functions.js:101:25
at Array.map (<anonymous>)
at convertArrayToObject (/Users/veller/Programming/seguidometro_bbb/node_modules/socialblade-com-api/functions.js:67:17)
at socialblade (/Users/veller/Programming/seguidometro_bbb/node_modules/socialblade-com-api/index.js:35:34)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async main (/Users/veller/Programming/seguidometro_bbb/socialblade.js:110:22)
Request failed too many times, aborting.
undefined
I'm not able to fetch the data from the api, It returns an error with the source even using 'twitter'
. Hope you could help me
It seems like the function convertUnit could have a little improvement because it was reporting false values for some youtube accounts.
Here for example the value of selenagomez subscribers is not converted correctly.
*Most recent data to 0, previous day not converted correctly
{
date: '2023/09/25',
subscribersDelta: 0,
subscribers: 34.1,
viewsDelta: 0,
views: 13309394169
},
{
date: '2023/09/26',
subscribersDelta: 0,
subscribers: 0,
viewsDelta: 0,
views: 13309394169
}
Here is a proposal for improvement:
function convertUnit(str) {
str = str.replace(/LIVE/g, '');
if (str.includes('K') || str.includes('M')) {
str = str.replace(/\./g, '')
}
str = str.replace(/K/g, '000').replace(/M/g, '000000');
return str;
}
One Line:
function convertUnit(str) {
return str.replace(/LIVE/g, '').replace(/K/g, '000').replace(/M/g, '000000').replace(/\./g, '');
}
Step 1: remove the "LIVE" info that could be there for the most recent datapoint
Step 2: if there is a . remove it, otherwise, the replacement of K or M will result in nothing afterwards
Step 3: Replace the K and M by the correct number of 0
New result for selenagomez from the proposal code snippet
{
date: '2023/09/25',
subscribersDelta: 0,
subscribers: 341000000,
viewsDelta: 0,
views: 13309394169
},
{
date: '2023/09/26',
subscribersDelta: 0,
subscribers: 341000000,
viewsDelta: 0,
views: 13309394169
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.