Abdul Khalid
Abdul Khalid

Reputation: 174

Integrating uber API(deeplinking) on Android app

Hi I want to integrate Ride with uber button on my APP. I made get request to api with parameters

'server_token': 'ma***********************u',
'start_latitude',
'start_longitude',
'end_latitude' 
'end_longitude'. 

and I got the response:

{
 "result": {
 "prices": [
    {
     "currency_code": "INR",
     "display_name": "uberGO",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹559-720",
    "high_estimate": 720,
    "localized_display_name": "uberGO",
    "low_estimate": 559,
    "minimum": 60,
    "product_id": "c8170d76-b67c-44b1-8c26-5f45541434d2",
    "surge_multiplier": 2
  },
  {
    "currency_code": "INR",
    "display_name": "uberGO",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹559-719",
    "high_estimate": 719,
    "localized_display_name": "uberGO",
    "low_estimate": 559,
    "minimum": 60,
    "product_id": "bc46ccfe-de64-4cad-b63a-7cf48e649a3e",
    "surge_multiplier": 2
  },
  {
    "currency_code": "INR",
    "display_name": "uberX",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹834-1,069",
    "high_estimate": 1069,
    "localized_display_name": "uberX",
    "low_estimate": 834,
    "minimum": 80,
    "product_id": "4da6a747-e0be-4f56-a3c7-3f30f22bf86d",
    "surge_multiplier": 2.4
  },
  {
    "currency_code": "INR",
    "display_name": "uberGO",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹834-1,069",
    "high_estimate": 1069,
    "localized_display_name": "uberGO",
    "low_estimate": 834,
    "minimum": 80,
    "product_id": "18656d0e-cc1b-4aa6-8146-92e605626caa",
    "surge_multiplier": 2.4
  },
  {
    "currency_code": "INR",
    "display_name": "uberXL",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹1,646-2,099",
    "high_estimate": 2099,
    "localized_display_name": "uberXL",
    "low_estimate": 1646,
    "minimum": 125,
    "product_id": "2ea18da2-bcf0-4df7-a7b8-a827e9945322",
    "surge_multiplier": 3.4
  },
  {
    "currency_code": "INR",
    "display_name": "uberXL",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹1,646-2,099",
    "high_estimate": 2099,
    "localized_display_name": "uberXL",
    "low_estimate": 1646,
    "minimum": 125,
    "product_id": "a4404842-e40a-471b-a7a5-13da3551e94f",
    "surge_multiplier": 3.4
    }
  ]
 }
}

Now I added this code on onclicklisteners of buttons:

String uri = "uber://?client_id=eFrzgz_2Du2KYUXIi3MKaNOWtxo3i77K&action=setPickup&pickup[latitude]=37.775818&pickup[longitude]=-122.418028&pickup[nickname]=UberHQ&pickup[formatted_address]=1455%20Market%20St%2C%20San%20Francisco%2C%20CA%2094103&dropoff[latitude]=37.802374&dropoff[longitude]=-122.405818&dropoff[nickname]=Coit%20Tower&dropoff[formatted_address]=1%20Telegraph%20Hill%20Blvd%2C%20San%20Francisco%2C%20CA%2094133&product_id=a1111c8c-c720-46c3-8534-2fcdd730040d";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(uri));
startActivity(intent); 


On clicking these buttons, it button redirects to uber APP with correct src and dst, but it's not picking correct uber category, like UberX, UberGo, UberL, etc. It always chooses default category. How to customize it to level that user just need to click a single button to book the cab.

Upvotes: 3

Views: 1024

Answers (1)

Alex Bitek
Alex Bitek

Reputation: 6557

The sample data used by the deep linking tests in the uber-rides-sdk for Android shows the same parameters for the intent that you send, so it should work.

uber:?action=setPickup&client_id=clientId&product_id=productId&pickup%5Blatitude%5D=32.1234&pickup%5Blongitude%5D=-122.3456&pickup%5Bnickname%5D=pickupNick&pickup%5Bformatted_address%5D=Pickup%20Address&dropoff%5Blatitude%5D=32.5678&dropoff%5Blongitude%5D=-122.6789&dropoff%5Bnickname%5D=pickupNick&dropoff%5Bformatted_address%5D=Dropoff%20Address

In the tests data I see that they also URL/percent encode the keys and values (e.g. pickup%5Blatitude%5D=32.1234), however in the documentation they don't.
Try to encode the data URI and retry.

Maybe you send the intent to the Uber app too late? That is, after the product id (the Uber car) no longer exists on the server, so the Uber app will not select it either.

Are those products returned from the sandbox API or the production API endpoints?

Can you validate the product id first by making a request to the GET /v1/products/{product_id} and ensure you get 200 OK HTTP response status code and the correct product details in the response body?

Upvotes: 1

Related Questions