jaebradley/tinder-client

Can't make import statement work

callixte-girard opened this issue · 14 comments

Hi!
I'm not a very experimented developper but I'm a bit familiar with NodeJS and ReactJS environments.
Nevertheless I can't make this library work integrated in a NodeJS app with the exact syntax you stated.
I tried these two solutions :

— The one you stated :

import { createClientFromFacebookLogin } from 'tinder-client'
const client = createClientFromFacebookLogin({ emailAddress: 'your facebook email address', password: 'your facebook password', })

I get an error at import statement.

— Another one :

const tinderClient = require('tinder-client')
const client = tinderClient.createClientFromFacebookLogin({ emailAddress: 'your facebook email address', password: 'your facebook password', })

I get another when launching app.

Please help, what am I doing wrong ?

@callixte-girard what is the error that you see? Can you add the stack trace?

Wow ! You answered fast. Thank you!

— With the solution you stated, I get :

`(function (exports, require, module, __filename, __dirname) { import { createClientFromFacebookLogin } from 'tinder-client';
^

SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)`

@callixte-girard this seems related to transpilation potentially. Are you using a transpiler like babel? Is your project open-source? Can I see a branch or repo where this is occurring?

The project is for myself so yeah, it's open source. But it's just the beginning, I only have index.js for now (+ package.json and package-lock.json as in every node project)
I don't know for babel, maybe. But if it's the case, I'm not aware of it.
Actually I just created my project with node default method :

mkdir automa-tinder && cd automa-tinder
npm init -y

Then I installed your package of course :

npm i tinder-client

I use WebStorm as an IDE. I tried with Visual Studio too but, as expected, I didn't change anything.

In my node_modules£ repertory, I indeed have a @babelfolder +tinder-client` and many others. Like in every npm project

If you're not using babel try this (obviously, you need to specify the arguments for createClientFromFacebookLogin)

const tinderClient = require('tinder-client');

tinderClient.createClientFromFacebookLogin();

@callixte-girard do you have a repository I can look at?

  1. I tried your solution. It works, but I get an error that tells me function unrecognised now :

const tinderClient = require('tinder-client');

const client = tinderClient.createClientFromFacebookLogin({
emailAddress: 'your facebook email address',
password: 'your facebook password',
});

const profile = client.getProfile();
console.log(profile);

Of course, I tried replacing with my actual email address and password, but it doesn't change anything.

Here is the error stack trace I get :

/Users/c/WebstormProjects/automa-tinder/index.js:9
const profile = client.getProfile();
^

TypeError: client.getProfile is not a function
at Object. (/Users/c/WebstormProjects/automa-tinder/index.js:9:24)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

  1. I don't have any yet, but I will create it now so that you can help me. Shall I include node_modules in my .gitignore or it must be posted on the repo too for you to check ?
    (sorry for little english mistakes)

Here is my repo : https://github.com/callixte-girard/automa-tinder
Please not I did not include node_modules because it was really large.
Thank you for taking a look !

I get an error that tells me function unrecognised now

This is because createClientFromFacebookLogin immediately returns a Promise.

You can see this in the README

image

as the example uses async/await.

Try this

tinderClient.createClientFromFacebookLogin({
  emailAddress: 'your facebook email address',
  password: 'your facebook password',
}).then(function(client) {
  var profile = client.getProfile();
  console.log('my profile is', profile);
}).catch(function(error) {
  console.error('why did I error', error);
});;

I knew about the promise but :

  • the await you put in the readme didn't work for me : WebStorm didn't recognise it. So I removed it.
  • I tried .then(console.log(client.getProfile())) but it didn't work...
  • I tried .then({ console.log(client.getProfile()) }) but it didn't work either...
    Now I understand why : it was a syntax problem.

I'm not getting an error anymore, but I don't get a JSON with the response either... Here is the output :

my profile is Promise { }

Anyway thank you very much for your help, I'm getting closer !

@callixte-girard .then takes a function, just FYI

I had a typo in my previous example - try this

tinderClient.createClientFromFacebookLogin({
  emailAddress: 'your facebook email address',
  password: 'your facebook password',
}).then(function(client) {
  return client.profile();
}).then(function(profile) {
  console.log('my profile is', profile);
}).catch(function(error) {
  console.error('why did I error', error);
});;

Just a little change to what you proposed : it's not return client.profile(); but return client.getProfile(); (I think you just mistyped) :

tinderClient.createClientFromFacebookLogin({
  emailAddress: 'your facebook email address',
  password: 'your facebook password',
}).then(function(client) {
  return client.getProfile();
}).then(function(profile) {
  console.log('my profile is', profile);
}).catch(function(error) {
  console.error('why did I error', error);
});

And this way, it works perfectly !!!!
Thanks a lot for all your help !

Ooof, sorry about the typo but I'm glad you got it to work!