Giter VIP home page Giter VIP logo

socialblade-com-api's People

Contributors

davideviolante avatar dependabot-preview[bot] avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

socialblade-com-api's Issues

Youtube URL Fix

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

TypeError: Cannot read property 'map' of null, when retrieving Twitter data for certain profiles

Error

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.

How to reproduce

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'))

Full error log

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

convertUnit Improvement

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
    }

Add TikTok Data

Social Blade has a TikTok section in beta, which can be valuable to add.

image

I believe the data of the graph is located in the same script publicly available (see below)

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.