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);
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 |
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/‘ |
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/‘ |
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
strapi.services.twitter.verifyCredentials();
get account settings
strapi.services.twitter.getAccountSettings();
get profile banner
strapi.services.twitter.getProfileBanner(screen_name);
Parameter | Type | Required | Explanation | Example |
---|
screen_name | string | yes | username 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);
{
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);
Parameter | Type | Required | Explanation | Example |
---|
count | integer | no | number of tweets returned, default 20 | 5 |
user timeline
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
strapi.services.twitter.getMentionTimeline(count);
Parameter | Type | Required | Explanation | Example |
---|
count | integer | no | number of tweets returned, default 20 | 5 |
User search
user lookup
strapi.services.twitter.lookupUser(screen_name);
Parameter | Type | Required | Explanation | Example |
---|
screen_name | string | yes | username of the twitter user | ’iarifiany’ |
user search
strapi.services.twitter.searchUser(query);
Parameter | Type | Required | Explanation | Example |
---|
query | string | yes | search query for user | ’iarifiany’ |
show user data
strapi.services.twitter.showUser(screen_name);
Parameter | Type | Required | Explanation | Example |
---|
screen_name | string | yes | username of the twitter user | ’iarifiany’ |