RapidAPI - Tweet Analysis
@ahmadbilaldev
code:
data:privatelast updated:2 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
search_twitter
Standard search API.
auth
(auths.twitter)
params
Q
 
string ·params.q
Optional
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
}
26
const oauthSignerUri = auths.twitter.oauth_signer_uri

const twitterParams = ["q", "tweet_mode", "geocode", "lang", "locale", "result_type", "count", "until", "since_id", "max_id", "include_entities"]
const {q, tweet_mode, geocode, lang, locale, result_type, count, until, since_id, max_id, include_entities} = params
p = params
p["tweet_mode"] = tweet_mode ? tweet_mode : "extended"

const config = {
    data: '',
    method: 'GET',
    url: `https://api.twitter.com/1.1/search/tweets.json`,
    params: p,
}

const token = {
    key: auths.twitter.oauth_access_token,
    secret: auths.twitter.oauth_refresh_token,
}

const signConfig = {
  token,
  oauthSignerUri
}
return (await require("@pipedreamhq/platform").axios(this, config, signConfig))
steps.
rapidapi
auth
to use OAuth tokens and API keys in code via theauths object
(auths.rapidapi)
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
}
34
let axios = require("axios").default;
let responseArray = [];

for(let i=0; (i<steps.search_twitter.$return_value.statuses.length); i++){
  const options = {
    method: 'POST',
    url: 'https://text-analysis12.p.rapidapi.com/sentiment-analysis/api/v1.1',
    headers: {
      'content-type': 'application/json',
      'x-rapidapi-host': 'text-analysis12.p.rapidapi.com',
      'x-rapidapi-key': auths.rapidapi
    },
    data: {
      language: 'english',
      text: steps.search_twitter.$return_value.statuses[i].full_text
    }
  };

    try {
      let response = await axios(options);
      responseArray.push(response.data);
      console.log(responseArray);
    } catch (error) {
      console.error(error.response);
    } 
}

let formattedArray = [['Tweet #', 'Sentiment' ,'Tweet Body']];
responseArray.forEach((tweet, index) => {
  formattedArray.push([index,tweet.sentiment, steps.search_twitter.$return_value.statuses[index].full_text])
  })
return formattedArray;
steps.
add_multiple_rows

Add multiple rows of data to a Google Sheet

configure

The drive to use. If you are connected with any Google Shared Drives, you can select it here by enabling "Structured Mode".

My Drive

The Google spreadsheet

Sheet Name

Provide an array of arrays. Each nested array should represent a row, with each element of the nested array representing a cell/column value (e.g., passing [["Foo",1,2],["Bar",3,4]] will insert two rows of data with three columns each). The most common pattern is to reference an array of arrays exported by a previous step (e.g., {{steps.foo.$return_value}}). You may also enter or construct a string that will JSON.parse() to an array of arrays.

 
Enter a value for Row Values