项目作者: flavea

项目描述 :
Strapi hook to integrate twitter to strapi
高级语言: JavaScript
项目地址: git://github.com/flavea/strapi-hook-twitter.git
创建时间: 2020-07-09T02:04:19Z
项目社区:https://github.com/flavea/strapi-hook-twitter

开源协议:MIT License

下载


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:
    1. module.exports = {
    2. settings: {
    3. ...
    4. "twitter": {
    5. "enabled": true, // set to enable the hook
    6. "debug": true, // to log the data
    7. "consumer_key": "consumer_key",
    8. "consumer_secret": "consumer_secret",
    9. "access_token_key": "access_token_key",
    10. "access_token_secret": "access_token_secret"
    11. }
    12. },
    13. };
  • 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:

  1. strapi.services.twitter.execute(api_path, method, parameters);
Parameter Type Required Explanation Values
api_path string yes the name of the API Check the official twitter documentation, example: account/verify_credentials
method string yes the API method post or get, also check the twitter doc
parameters object no the parameter required by the api check the twitter doc

Tweet

send a tweet
  1. strapi.services.twitter.tweet(status, attachment_url);
Parameter Type Required Explanation Example
status string yes the tweet you want to send ‘Hello World’
attachment_url string no link you want to include in the tweet https://twitter.com/
reply to a tweet/add to thread
  1. strapi.services.twitter.tweet(status, tweet_id, attachment_url);
Parameter Type Required Explanation Example
status string yes the tweet you want to send ‘Hello World’
tweet_id string yes the id of the tweet you want to reply to ‘124343’
attachment_url string no link you want to include in the tweet https://twitter.com/
search tweets
  1. strapi.services.twitter.searchTweets(query, count, result_type);
Parameter Type Required Explanation Example
query string yes your search query ‘Hello’
count integer no the amount of tweets retrieved. default: 20 ‘124343’
result_type string no type of search results. Choices: mixed (default), recent, popular ‘mixed’

Account

verify credentials
  1. strapi.services.twitter.verifyCredentials();
get account settings
  1. strapi.services.twitter.getAccountSettings();
get profile banner
  1. strapi.services.twitter.getProfileBanner(screen_name);
Parameter Type Required Explanation Example
screen_name string yes username of the twitter user ‘iarifiany’
remove profile banner
  1. strapi.services.twitter.removeProfileBanner();
update profile

Data: object, check the documentation for the update data

  1. strapi.services.twitter.updateProfile(data);

example:

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

Authentication

get bearer token
  1. strapi.services.twitter.getBearerToken();
get oauth token
  1. strapi.services.twitter.OAuth(callback_url);
Parameter Type Required Explanation Example
callback_url string yes callback url https://localhost:3000/callback

return:

  1. {
  2. token: oauth_token,
  3. token_secret: oauth_token_secret
  4. }
get access token
  1. strapi.services.twitter.getAccessToken(oauthVerifier, oauthToken);

return:

  1. {
  2. access_token: oauth_token,
  3. access_token_secret: oauth_token_secret,
  4. user_id: user_id,
  5. screen_name: screen_name
  6. }

Timeline

home timeline
  1. strapi.services.twitter.getHomeTimeline(count);
Parameter Type Required Explanation Example
count integer no number of tweets returned, default 20 5
user timeline
  1. strapi.services.twitter.getHomeTimeline(count, screen_name);
Parameter Type Required Explanation Example
count integer no number of tweets returned, default 20 5
screen_name string yes username of the twitter user ‘iarifiany’
mentions timeline
  1. strapi.services.twitter.getMentionTimeline(count);
Parameter Type Required Explanation Example
count integer no number of tweets returned, default 20 5
user lookup
  1. strapi.services.twitter.lookupUser(screen_name);
Parameter Type Required Explanation Example
screen_name string yes username of the twitter user ‘iarifiany’
  1. strapi.services.twitter.searchUser(query);
Parameter Type Required Explanation Example
query string yes search query for user ‘iarifiany’
show user data
  1. strapi.services.twitter.showUser(screen_name);
Parameter Type Required Explanation Example
screen_name string yes username of the twitter user ‘iarifiany’