0.0.1 • Published 12 months ago

social-media-analytics-client v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

@xorddotcom/social-media-analytics

A package which provides you with the analytics of major social media platforms.

Supported social media platforms

  • Facebook
  • Instagram
  • Tiktok
  • Linkedin
  • Twitter
  • Youtube
  • Twitch

Installation Guide

Install the package in your js/ts appication.

npm install @xorddotcom/social-media-analytics
OR
yarn add @xorddotcom/social-media-analytics

Integration Guide

Facebook

Create facebook developer account. (https://developers.facebook.com/)

Create facebook app. (https://developers.facebook.com/apps/?show_reminder=true)

Configure facebook login for your facebook app. (https://developers.facebook.com/apps/{your-app-id}/fb-login/settings/)

Add your application's server URL in Valid OAuth Redirect URIs input.

Import Facebook constructor from the sdk. Create Facebook instance.

import { Facebook } from '@xorddotcom/social-media-analytics';

const facebook = new Facebook({
  apiKey: '',
  apiSecret: '',
  redirectLink: '',
});

You'll find apiKey as App ID and apiSecret as App Secret from your facebook app's basic settings.

Methods

facebook.getAuthorizationLink()

returns authorization link which you can attach to your login with facebook button. After successful authorization facebook will redirect user to the redirect link you provided in the constructor with authorization code in query params.

facebook.getUserAccessToken(_authorizationToken)

returns user's access token which is obtained after successful authorization from authorization link above.

facebook.getUserDetails(_accessToken): UserObject

returns user's profile info. Function takes in access token which is obtained using getUserAccessToken function.

facebook.getUserLatestPosts(_accessToken): PostObject[]

returns user's latest posts list. Function takes in access token which is obtained using getUserAccessToken function.

facebook.getPostDetails(_postIdentifiers[], _accessToken): PostObject[]

returns user's post details list. Function takes in an array of post identifiers, these are obtained using getUserLatestPosts function. Function takes in access token which is obtained using getUserAccessToken function.

Response Objects

User Object

propertyvalue
aboutstring
emailstring
first_namestring
last_namestring
middle_namestring
namestring
linkstring

Post Object

propertyvalue
engagementsnumber
impressionsnumber
reactionsnumber
commentsnumber
sharesnumber
descriptionstring
created_timestring
updated_timestring
messagestring

Instagram

Before you start you'll need.

  • An Instagram Business Account or Instagram Creator Account
  • A Facebook Page connected to that account
  • A Facebook Developer account that can perform Tasks on that Page
  • A registered Facebook App with Basic settings configured

Configure facebook login for your facebook app with permissions. (https://developers.facebook.com/apps/{your-app-id}/fb-login/settings/)

Add your application's server URL in Valid OAuth Redirect URIs input.

Import Instagram constructor from the sdk. Create Instagram instance.

import { Instagram } from '@xorddotcom/social-media-analytics';

const instagram = new Instagram({
  apiKey: '',
  apiSecret: '',
  redirectLink: '',
});

You'll find apiKey as App ID and apiSecret as App Secret from your facebook app's basic settings.

Methods

instagram.getAuthorizationLink()

returns authorization link which you can attach to your login with instagram button. After successful authorization instagram will redirect user to the redirect link you provided in the constructor with authorization code in query params.

instagram.getUserAccessToken(_authorizationToken)

returns user's access token which is obtained after successful authorization from authorization link above.

instagram.getUserDetails(_accessToken): UserObject

returns user's profile info. Function takes in access token which is obtained using getUserAccessToken function.

instagram.getUserLatestPosts(_accessToken): PostObject[]

returns user's latest posts list. Function takes in access token which is obtained using getUserAccessToken function.

instagram.getPostDetails(_postIdentifiers[], _accessToken): PostObject[]

returns user's post details list. Function takes in an array of post identifiers, these are obtained using getUserLatestPosts function. Function takes in access token which is obtained using getUserAccessToken function.

Response Objects

User Object

propertyvalue
idstring
namestring
usernamestring
profile_picture_urlstring
biographystring
mediaPostObject[]

Post Object

propertyvalue
engagementsnumber
impressionsnumber
likesnumber
commentsnumber
descriptionstring
created_timestring
updated_timestring
messagestring

Tiktok

Create Tiktok developer account.

Create Tiktok app. (https://developers.tiktok.com/apps/)

Fill in the basic information on Tiktok application dashboard.

Add login kit and Video kit as product in your Tiktok application.

In login kit find input with label Redirect domain, and add your application server's domain in it.

In Tiktok api section found at the bottom of Tiktok application dashboard. Add user.info.basic and video.list as scopes.

Submit your app for review. Tiktok SDK won't work if your app is not approved.

Import Tiktok constructor from the sdk. Create Tiktok instance.

import { Tiktok } from '@xorddotcom/social-media-analytics';

const tiktok = new Tiktok({
  clientId: '',
  clientSecret: '',
});

You'll find clientKey and clientSecret from your tiktok application's dashboard.

Methods

tiktok.getAuthorizationLink(_redirectLink)

returns authorization link which you can attach to your login with tiktok button. After successful authorization tiktok will redirect user to the redirect link you provided in function param with authorization code in query params.

tiktok.getUserAccessToken(_authorizationToken)

returns user's access token which is obtained after successful authorization from authorization link above.

tiktok.refreshAccessToken(_refreshToken)

returns user's refreshed access token which is obtained after successful authorization from authorization link above.

tiktok.getUserProfileInfo(_accessToken): UserObject

returns user's profile info. Function takes in access token which is obtained using getUserAccessToken function.

tiktok.getUserVideoList(_accessToken, _maxResults?, _sort?): VideoObject[]

returns user's latest video list. Function takes in access token which is obtained using getUserAccessToken function.

tiktok.getVideoDetails(_postIdentifiers, _accessToken): VideoObject[]

returns user's video details list. Function takes in an array of post identifiers, which can be video ids or video urls.

Response Objects

User Object

propertyvalue
avatar_urlstring
bio_descriptionstring
display_namestring
follower_countnumber
is_verifiedboolean
open_idstring
profile_deep_linkstring
likes_countnumber
following_countnumber
union_idstring

Video Object

propertyvalue
engagementsnumber
impressionsnumber
idstring
create_timenumber
cover_image_urlstring
share_urlstring
video_descriptionstring
durationnumber
heightnumber
widthnumber
titlestring
embed_htmlstring
embed_linkstring
like_countnumber
comment_countnumber
share_countnumber
view_countnumber

Twitter

Create twitter developer account. (https://developer.twitter.com/en/portal/petition/essential/basic-info)

You have to apply for developer account in order to use twitter's api service

Create twitter app. (https://developer.twitter.com/en/portal/projects-and-apps)

Get your bearer token by clicking on key icon. (https://developer.twitter.com/en/portal/projects/{projectId}/apps/{appId}/keys)

Import Twitter constructor from the sdk. Create Twitter instance.

import { Twitter } from '@xorddotcom/social-media-analytics';

const TwitterBearerToken = 'your app bearer token';

const twitter = new Twitter({ apiToken: TwitterBearerToken });

You'll find token as Bearer Token from your twitter Projects and Apps selected app tab.

Methods

twitter.getTweetDetails(_tweetId[])

returns returns details and statistics of tweet with engagements and impressions using list of tweet ids, tweet id can be get from url bar of tweet detail page

twitter.getLatestTweets(_username[])

returns list of most recent 10 tweets of users using username, tweets id can be get from url bar of tweet detail page

twitter.getUserDetails(_userName[])

returns list of user details using list of twitter username, tweets id can be get from url bar of tweet detail page

Youtube

Create gmail account.(https://accounts.google.com/signup/v2/webcreateaccount?flowName=GlifWebSignIn&flowEntry=SignUp)

Create project on Google console. (https://console.cloud.google.com/)

Enable youtube v3 apis from. (https://console.cloud.google.com/apis/library/youtube.googleapis.com)

Create Api key for your app integration from. (https://console.cloud.google.com/apis/credentials)

Import youtube constructor from the sdk. Create youtube instance.

import { Youtube } from '@xorddotcom/social-media-analytics';

const youtubeBearerToken = 'your app api token';

const youtube = new Youtube({ apiToken: youtubeBearerToken });

You'll find token as Api token from your google console project (https://console.cloud.google.com/apis/credentials).

Methods

youtube.getVideoDetails(videoUrls[])

returns details of video(s) with engagements and impressions using list of video urls, videos url can be get from url bar of video page

youtube.getLatestVideos(videoUrls[])

returns list of most recent 10 videos of channel(s) using list of video urls, videos url can be get from url bar of video page

youtube.getChannelDetails(channelUrls[])

returns list of channel details using array of channel urls in an array, videos url can be get from url bar of video page of youtube

Response Objects

Channel Object

propertyvalue
idstring
titlestring
descriptionstring
customUrlstring
publishedAtstring
thumbnailsObject
countrystring
localizedObject
viewCountstring
subscriberCountstring
hiddenSubscriberCountboolean
videoCountstring

Video Object

propertyvalue
publishedAtstring
channelIdstring
titlestring
descriptionstring
thumbnailsObject
channelTitlestring
tagsArray
categoryIdstring
liveBroadcastContentstring
localizedObject
viewCountstring
likeCountstring
favoriteCountstring
commentCountstring
impressionsnumber
engagementsnumber

LinkedIn

Create linkedIn account.(https://www.linkedin.com/login)

Create an App. (https://developer.linkedin.com/) + user will need a linkedIn page to connect their app.

verify your app with page. (https://www.linkedin.com/developers/apps/{your app id}/settings)

set your authorized redirect urls to allow access to your url. (https://www.linkedin.com/developers/apps/{your app id}/auth)

User have to apply for Marketing Developer Platform in order to get access to api to fetch organization and user data (https://console.cloud.google.com/apis/credentials) applying to marketing developer platform may take some days to verify your access request. although app cannot get access to user data due to resource restriction from linkedIn.

Get your application creadentions such as Client ID and Client Secret (https://www.linkedin.com/developers/apps/{your app id}/auth)

Import LinkedIn constructor from the sdk. Create linkedIn instance.

import { LinkedIn } from '@xorddotcom/social-media-analytics';

const clientId = '78owxoz0fwu37s';
const clientSecret = 'aSypQ3MbeDDDAzAT';
const redirect_uri = 'https://testsocialapis.web.app/login/linkedin'; //should be same as you setted on application auth page


const linkedIn = new LinkedIn({
    clientId,
    clientSecret,
    apiUrl: 'https://testsocialapis.web.app/login/linkedin',
  });

Methods

linkedIn.getAuthorizationLink(redirect_uri)

returns authorization link which user can add on their auth button. This will redirect user to the social media platform and will ask them to authorize the given permissions. After successful authorization social media platform will redirect on the given redirect link in the constructor param with the auth code in the query params, which should be extracted and used to give them the access token for that particular user.

linkedIn.getAccessToken(_authenticationCode: string, _redirectLink: string)

returns user access token object by using authentication code obtain by using getAuthorizationlink methods url. access token then can be use to authenticate user while using other methods by sending access token in methods _accessToken parameter.

linkedIn.getAccessTokenFromRefreshToken(_refreshToken: string)

returns user access token object by using refresh token obtain by using getAccessToken methods url. access token then can be use to authenticate user while using other methods.

linkedIn.getOrgLatestPosts(_accessToken: string, _orgNames: string[])

returns organization's latest 10 posts list of multiple organizations taken as an array in parameter. Function takes in access token which is obtained using getAccessToken function.

linkedIn.getOrgPostDetails(_accessToken: string, _postUrls: string[])

returns organization's post details of multiple urls taken in an array as parameter. Function takes in array of post urls, these are obtained from url of post page in linkedIn function. Function takes in access token which is obtained using getUserAccessToken function.

linkedIn.getOrgDetails(_accessToken: string,_orgNames: string[],_getFollowers: boolean = true)

returns organization details by name. function take list of organization names as parameters and fetch details for all. second parameter "_getFollowers" is optional and true by default.

Response Objects

Organization Object

propertyvalue
orgIdstring
orgNamestring
orgWebsitestring
orgAddressnumber
orgLogoboolean
orgFollowersstring

Post Object

propertyvalue
isReshareDisabledByAuthorboolean
createdAtnumber
postStatestring
lastModifiedAtnumber
visibilitystring
publishedAtnumber
titlestring
isEditedByAuthorboolean
content{ media: { id: string } }
totalFirstLevelCommentsnumber
aggregatedTotalCommentsnumber
likedByCurrentUserboolean
totalFirstLevelLikesnumber
aggregatedTotalLikesnumber
impressionsnumber
engagementsnumber

Twitch

Create twitch account by signing up or loging in.(https://www.twitch.tv/)

Create an App. (https://dev.twitch.tv/console), user will need a twitch account with two factor authentication enabled.

Add your redirected urls.

Create secret and save it to integrate with your app. (https://dev.twitch.tv/console/apps/{your app id})

Copy client id with client secret as well.

Get your application creadentions such as Client ID and Client Secret

Import Twitch constructor from the sdk. Create twitch instance.

import { Twitch } from '@xorddotcom/social-media-analytics';

const clientSecret = 'your client secret';

const clientId = 'your client id';
const twitchApp = new Twitch({ clientId: clientId, clientSecret: clientSecret });

Methods

twitchApp.getAccessToken()

returns authorization link which user can add on their auth button. This will redirect user to the social media platform and will ask them to authorize the given permissions. After successful authorization social media platform will redirect on the given redirect link in the constructor param with the auth code in the query params, which should be extracted and used to give them the access token for that particular user.

twitchApp.getVideos(_videoUrls: string[], _accessToken: string)

returns user list of user details by username. array of username and a access token is required to fetch details. access token can be retrieve by using getAccessToken methods.

twitchApp.getClips(_clipsUrls: string[], _accessToken:string)

returns list of clips from live streams details by clip url. array of clip url and a access token is required to fetch details. access token can be retrieve by using getAccessToken methods.

twitchApp.getLatestLiveStreams(_userNames_: string[], _accessToken:string)

returns list of latest videos including streams and clips details by list of usernames present in url. array of video Ids and a access token is required to fetch details. access token can be retrieve by using getAccessToken methods.

twitchApp.getUsers(_userNames_: string[], _accessToken:string)

returns user list of user details by username. array of username and a access token is required to fetch details. access token can be retrieve by using getAccessToken methods.

Response Objects

User/Channel Object

propertyvalue
idstring
loginstring
display_namestring
typestring
broadcaster_typestring
descriptionstring
profile_image_urlstring
offline_image_urlstring
view_countnumber
followersnumber
email?string
created_atstring

Live Stream Object

propertyvalue
idstring
user_idstring
user_loginstring
user_namestring
game_idstring
game_namestring
typestring
titlestring
viewer_countnumber
started_atstring
languagestring
thumbnail_urlstring
tag_idsArray
is_maturefalse

Video Object

propertyvalue
idstring
stream_idstring
user_idstring
user_loginstring
user_namestring
titlestring
descriptionstring
created_atstring
published_atstring
urlstring
thumbnail_urlstring
viewablestring
view_countnumber
languagestring
typestring
durationstring
muted_segmentsnullstring

Clip Object

propertyvalue
idstring
urlstring
embed_urlstring
broadcaster_idstring
broadcaster_namestring
creator_idstring
creator_namestring
video_idstring
game_idstring
languagestring
titlestring
view_countnumber
created_atstring
thumbnail_urlstring
durationnumber
vod_offsetnumber