Strapi Hook Twitter

Published  at  06:00 AM

strapi-hook-twitter

This package is used to integrate twitter api to algolia.

Table of contents generated with markdown-toc

setup

  • Create an app on twitter
  • Get the consumer key, consumer secret, access token key, and access token secret from the app page
  • Create or update ./config/hook.js in your algolia code folder, add the following data to the file:
  module.exports = {
settings: {
  ...
  "twitter": {
"enabled": true, // set to enable the hook
"debug": true, // to log the data
"consumer_key": "consumer_key",
"consumer_secret": "consumer_secret",
"access_token_key": "access_token_key",
"access_token_secret": "access_token_secret"
  }
},
  };
  • Use as service in models, etc

future update

support for streams, create functions for all APIs

usage

The functions will return the response of the API call.

Fetch Unlisted APIs

For APIs that don’t have a defined function in this package, you can call the API by executing the following code:

strapi.services.twitter.execute(api_path, method, parameters);
ParameterTypeRequiredExplanationValues
api_pathstringyesthe name of the APICheck the official twitter documentation, example: account/verify_credentials
methodstringyesthe API methodpost or get, also check the twitter doc
parametersobjectnothe parameter required by the apicheck the twitter doc

Tweet

send a tweet
strapi.services.twitter.tweet(status, attachment_url);
ParameterTypeRequiredExplanationExample
statusstringyesthe tweet you want to send’Hello World’
attachment_urlstringnolink you want to include in the tweethttps://twitter.com/
reply to a tweet/add to thread
strapi.services.twitter.tweet(status, tweet_id, attachment_url);
ParameterTypeRequiredExplanationExample
statusstringyesthe tweet you want to send’Hello World’
tweet_idstringyesthe id of the tweet you want to reply to’124343’
attachment_urlstringnolink you want to include in the tweethttps://twitter.com/
search tweets
strapi.services.twitter.searchTweets(query, count, result_type);
ParameterTypeRequiredExplanationExample
querystringyesyour search query’Hello’
countintegernothe amount of tweets retrieved. default: 20’124343’
result_typestringnotype of search results. Choices: mixed (default), recent, popular’mixed’

Account

verify credentials
strapi.services.twitter.verifyCredentials();
get account settings
strapi.services.twitter.getAccountSettings();
get profile banner
strapi.services.twitter.getProfileBanner(screen_name);
ParameterTypeRequiredExplanationExample
screen_namestringyesusername of the twitter user’iarifiany’
remove profile banner
strapi.services.twitter.removeProfileBanner();
update profile

Data: object, check the documentation for the update data

strapi.services.twitter.updateProfile(data);

example:

strapi.services.twitter.updateProfile({ Name: 'Ilma'});
update profile banner
strapi.services.twitter.updateProfileBanner(fileData);
update profile image
strapi.services.twitter.updateProfileImage(fileData);

Authentication

get bearer token
strapi.services.twitter.getBearerToken();
get oauth token
strapi.services.twitter.OAuth(callback_url);
ParameterTypeRequiredExplanationExample
callback_urlstringyescallback urlhttps://localhost:3000/callback
return:
{
  token: oauth_token,
  token_secret: oauth_token_secret
}
get access token
strapi.services.twitter.getAccessToken(oauthVerifier, oauthToken);

return:

{
  access_token: oauth_token,
  access_token_secret: oauth_token_secret,
  user_id: user_id,
  screen_name: screen_name
}

Timeline

home timeline
strapi.services.twitter.getHomeTimeline(count);
ParameterTypeRequiredExplanationExample
countintegernonumber of tweets returned, default 205
user timeline
strapi.services.twitter.getHomeTimeline(count, screen_name);
ParameterTypeRequiredExplanationExample
countintegernonumber of tweets returned, default 205
screen_namestringyesusername of the twitter user’iarifiany’
mentions timeline
strapi.services.twitter.getMentionTimeline(count);
ParameterTypeRequiredExplanationExample
countintegernonumber of tweets returned, default 205
user lookup
strapi.services.twitter.lookupUser(screen_name);
ParameterTypeRequiredExplanationExample
screen_namestringyesusername of the twitter user’iarifiany’
user search
strapi.services.twitter.searchUser(query);
ParameterTypeRequiredExplanationExample
querystringyessearch query for user’iarifiany’
show user data
strapi.services.twitter.showUser(screen_name);
ParameterTypeRequiredExplanationExample
screen_namestringyesusername of the twitter user’iarifiany’

Terms of Use

  • Do not remove the credit completely or make them invisible, you may replace it to a visible place.
  • Do not steal the code or take parts of the codes and put them in your own theme, do not use them as base code too.
  • Do not redistribute my codes unless you have my permission, please just redirect people to this page OR reblog my posts about the codes.
  • Altering the code is allowed but keep the credit intact.
  • You may remove the credit only for base codes.