slysid slysid - 1 month ago 10
Objective-C Question

UBER iOS SDK - 401 error

I am following the UBER iOS SDK documentation to integrate uber into my app.

I am trying to integrate "Ride Request Button" into my app and I copy pasted the example code from the documentation

UBSDKRideRequestButton *button = [[UBSDKRideRequestButton alloc] init];
[self view] addSubview:button];
UBSDKRidesClient *ridesClient = [[UBSDKRidesClient alloc] init];
CLLocation *pickupLocation = [[CLLocation alloc] initWithLatitude: 37.787654 longitude: -122.402760];
CLLocation *dropoffLocation = [[CLLocation alloc] initWithLatitude: 37.775200 longitude: -122.417587];
__block UBSDKRideParametersBuilder *builder = [[UBSDKRideParametersBuilder alloc] init];
builder = [builder setPickupLocation: pickupLocation];
builder = [builder setDropoffLocation: dropoffLocation];
[ridesClient fetchCheapestProductWithPickupLocation: pickupLocation completion:^(UBSDKUberProduct* _Nullable product, UBSDKResponse* _Nullable response) {
if (product) {
builder = [builder setProductID: product.productID];
button.rideParameters = [builder build];
[button loadRideInformation];

The block UBSDKResponse (response.response) looks as below

<NSHTTPURLResponse: 0x15c6c1eb0> { URL: } { status code: 401, headers {
Connection = "keep-alive";
"Content-Length" = 63;
"Content-Type" = "application/json";
Date = "Thu, 01 Sep 2016 21:39:12 GMT";
Server = nginx;
"Strict-Transport-Security" = "max-age=0";
"X-Content-Type-Options" = nosniff;
"X-Uber-App" = "uberex-sandbox, migrator-uberex-sandbox-optimus";
"X-XSS-Protection" = "1; mode=block";
} }

I have configured the UberClient ID in my app in info.plist file. Not sure what I am missing to get a 401 response.



You just need to add the server token to your Info.plist.

Copy this snippet into your Info.plist (right click and select Open As > Source Code) and replace [Your Server Token] with the Server Token from your dashboard (make sure you use the server token corresponding to your client ID).

<string>[Your Server Token]</string>

Hope this helps!