I edited the whole topic because I gave a great read about the whole API and now I'm having another problem ... I'll try to leave as much details as possible here.
The error you are giving is 401 of uber api, but, I did everything right ... My INDEX.html looks like this:
index.html
<html>
<head>
<title>Party Invitation</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<section>
<h1>Party</h1>
<div class="info-container">
<span class="info-header">When</span>
<span class="info when">September 18, 2014 at 6:00pm</span>
</div>
<div class="info-container">
<span class="info-header">Where</span>
<span class="info where">Thinkful HQ</span>
</div>
<img class="map" src="http://maps.googleapis.com/maps/api/staticmap?center=40.7248,-73.99597&zoom=17&format=png&sensor=false&size=280x280&maptype=roadmap&style=element:geometry.fill|color:0xf4f4f4&markers=color:red|40.7248,-73.99597&scale=2" alt="">
<div class="button">
<p id="time">ESTIMATING TIME</p>
</div>
</section>
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/uber.js"></script>
</body>
And then my uber.js is like this:
uber.js
// Uber API Constants
var uberClientId = "RxGbzH***************"
, uberServerToken = "h_hqd3L4***************";
// Create variables to store latitude and longitude
var userLatitude
, userLongitude
, partyLatitude = 19.3256725
, partyLongitude = -43.1579731;
navigator.geolocation.watchPosition(function(position) {
// Update latitude and longitude
userLatitude = position.coords.latitude;
userLongitude = position.coords.longitude;
// Query Uber API if needed
getEstimatesForUserLocation(userLatitude, userLongitude);
});
function getEstimatesForUserLocation(latitude,longitude) {
$.ajax({
url: "https://api.uber.com/v1/estimates/price",
headers: {
Authorization: "KA.ey**********************************************************************************************************************************" + uberServerToken
},
data: {
start_latitude: latitude,
start_longitude: longitude,
end_latitude: partyLatitude,
end_longitude: partyLongitude
},
success: function(result) {
console.log(result);
}
});
}
And this is the error that is appearing
And my uber control panel is like this
Can anyone tell me why they are giving these two errors on the console? I do not know what to do
=\
As I can see - your application is not set-up properly. You don't have Redirect URL, Privacy Policy and because you are making API calls from JS - Origin URL:
So add something like:
Redirect URL: http://localhost:7000/redirect
Privacy Policy: http://localhost:7000/privacy
Origin URL: http://localhost:7000
I'm not sure where did you get your access token - because you don't have your app set up properly - but even then this will not work because your header is invalid. You are missing token type "Bearer" for access_token. So, in this case, your code should be like:
headers: {
Authorization: "Bearer KA.ey**********************************************************************************************************************************"
}
If you want to use Server Token:
headers: {
Authorization: "Token uberServerToken"
}
Please read our documentation for more info.