Twitter Engagement API Implementation

Hi,

I am trying to implement the Twitter engagement API with a twitter App I created using Wix back-end code. I found a GitHub repository with a Node.JS implementation of the twitter API and I was wondering if there was any way to edit it to be able to pull engagement data from the API through Wix Code.

Node.JS Repo:

Twitter Engagement Dev Page:
https://developer.twitter.com/en/docs/metrics/get-tweet-engagement/overview.html

Thank you!

Npm support is coming up soon. In the meantime you could simply copy the Npm lib code to your backend and use it.

It was my understanding that Wix Code is not running Pure JS and therefore there are some limitations.

Such as in the NodeJS repo in my original post, using process.env. I am aware that Wix has something similar with wix-window, however, I also know that you can only use it on the front end and you cannot call it from the Backend.

Code snippet:
var config = process.env;
this.consumerKey = config.twitterConsumerKey;
this.consumerSecret = config.twitterConsumerSecret;

Would you have any suggestions as to how I should copy the NPM code over to Wix and edit it for it to integrate with Wix code properly?

Thank you!

Hey,

Wix code do support Pure JS, however since we are running your code in a serverless environment there are some boundaries and abstractions we would like to keep, for security reasons, node version, file system, OS, backward compatibility etc. so terminology-wise there are some boundaries vs what you are able to do running your node server yourself :slight_smile:
we do support pure JS and http api calls, you should further dive into the specific implementation you mentioned above by BoyCook (there are a few such clients), it might need little tweaking mainly around the way it finds its configuration and implementation of oauth. for one, downloading the code from the npm repo show the git code does not match the npm module, so the above process.env snippet does not exist there (which by the way is currently supported by wix code):

function Twitter(config) {
    this.consumerKey = config.consumerKey;
    this.consumerSecret = config.consumerSecret;
    this.accessToken = config.accessToken;
    this.accessTokenSecret = config.accessTokenSecret;
    this.callBackUrl = config.callBackUrl;
    this.baseUrl = 'https://api.twitter.com/1.1';
    this.oauth = new OAuth(
        'https://api.twitter.com/oauth/request_token',
        'https://api.twitter.com/oauth/access_token',
        this.consumerKey,
        this.consumerSecret,
        '1.0',
        this.callBackUrl,
        'HMAC-SHA1'
    );
}

if you want to further look into that please let us know if you need any specific help, if you end up creating your own npm package out of it we might be able to share it within the wix code eco system

good luck,
Shlomi