This package is used to integrate twitter api to algolia.
Table of contents generated with markdown-toc
- 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,
"debug": true,
"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
support for streams, create functions for all APIs
The functions will return the response of the API call.
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' |
strapi.services.twitter.verifyCredentials();
strapi.services.twitter.getAccountSettings();
strapi.services.twitter.getProfileBanner(screen_name);
| Parameter |
Type |
Required |
Explanation |
Example |
| screen_name |
string |
yes |
username of the twitter user |
'iarifiany' |
strapi.services.twitter.removeProfileBanner();
Data: object, check the documentation for the update data
strapi.services.twitter.updateProfile(data);
example:
strapi.services.twitter.updateProfile({ Name: 'Ilma'});
strapi.services.twitter.updateProfileBanner(fileData);
strapi.services.twitter.updateProfileImage(fileData);
strapi.services.twitter.getBearerToken();
strapi.services.twitter.OAuth(callback_url);
{
token: oauth_token,
token_secret: oauth_token_secret
}
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
}
strapi.services.twitter.getHomeTimeline(count);
| Parameter |
Type |
Required |
Explanation |
Example |
| count |
integer |
no |
number of tweets returned, default 20 |
5 |
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' |
strapi.services.twitter.getMentionTimeline(count);
| Parameter |
Type |
Required |
Explanation |
Example |
| count |
integer |
no |
number of tweets returned, default 20 |
5 |
strapi.services.twitter.lookupUser(screen_name);
| Parameter |
Type |
Required |
Explanation |
Example |
| screen_name |
string |
yes |
username of the twitter user |
'iarifiany' |
strapi.services.twitter.searchUser(query);
| Parameter |
Type |
Required |
Explanation |
Example |
| query |
string |
yes |
search query for user |
'iarifiany' |
strapi.services.twitter.showUser(screen_name);
| Parameter |
Type |
Required |
Explanation |
Example |
| screen_name |
string |
yes |
username of the twitter user |
'iarifiany' |