I am trying to integrate uber APIs on a website using javascript for getting info like cab fare or time required between 2 places.
I am very new to javascript. I am following the steps as shown on Github: https://github.com/shernshiou/node-uber#method-overview
It is the official recommendation from Uber.
When i am trying to do this :
var Uber = require('node-uber');
I get an error that can't find variable require.
I have tried to search on the internet but only lead that I have gotten is that 'require' is a function of node.js and I can use requirejs for getting the file but I haven't got any success yet.
Can someone help me?
Edited: Code :
function uberSignIn(){
var Uber = require('node-uber');
var uber = new Uber({
client_id: '8CTT3TcU5RUcxsapr8wWZpwxVO8180aM',
client_secret: '',
server_token: 'nc4Bxk-HR6ja7EOA9MaAZvPI4sIizimiqiKGVfNX',
redirect_uri: 'file:///Users/akshay/Desktop/dev_work/travelSathi/index.html',
name: 'travelsathi',
language: 'en_US', // optional, defaults to en_US
sandbox: false, // optional, defaults to false
//proxy: 'PROXY URL' // optional, defaults to none
});
}
答案 0 :(得分:1)
You should use Browserify
to use that API wrapper which is for NodeJS. Otherwise, it's not compatible to use on web.
You can take a look at this repo.
You should set-up Nodejs on your computer. Then you need to install node-browserify
as below;
npm install -g browserify
.
Then in a simple way, you can use it as below;
browserify uber-api-wrapper.js > uber-api-web.js
.
Your uber-api-wrapper.js should look as below;
var Uber = require('node-uber');