UBER iOS SDK - 401错误

时间:2016-09-01 21:51:31

标签: ios objective-c uber-api

我正在关注UBER iOS SDK文档,将uber集成到我的应用程序中。

https://github.com/uber/rides-ios-sdk

我正在尝试整合" Ride Request Button"进入我的应用程序,我复制粘贴文档中的示例代码

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];
    }
}];

块UBSDKResponse(response.response)如下所示

<NSHTTPURLResponse: 0x15c6c1eb0> { URL: https://sandbox-api.uber.com/v1/products?latitude=37.787654&longitude=-122.40276 } { 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";
} }

我已在info.plist文件中的应用中配置了UberClient ID。不知道我错过了什么来获得401响应。

由于

2 个答案:

答案 0 :(得分:1)

您只需将服务器令牌添加到Info.plist。

将此代码段复制到Info.plist(右键单击并选择打开方式&gt;源代码)并将[Your Server Token]替换为dashboard中的服务器令牌(确保使用与客户端ID对应的服务器令牌。)

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

希望这有帮助!

答案 1 :(得分:0)

我们在集成401时遇到错误Swift SDK,因此,请您提供一些与我们的查询相关的解决方案。

 fileprivate func getData() {

        let pickupLocation = CLLocation(latitude: 28.5355, longitude: 77.3910)
        let dropoffLocation = CLLocation(latitude: 28.5865, longitude: 77.3963)
        let builder = RideParametersBuilder()
        builder.pickupLocation = pickupLocation
        builder.dropoffLocation = dropoffLocation

        ridesClient.fetchProducts(pickupLocation: pickupLocation) { products, response in
            print(response.response)
            print(products)
            uberCabProductList.removeAll()

            for i in 0..<products.count {
                uberCabProductList.append(products[i])
            }

            print("uberCabProductList:: ",uberCabProductList)
            self.selectRidePopUpVC()
            guard let uberX = products.filter({$0.productGroup == .uberXL}).first else {
                // Handle error, UberX does not exist at this location
                return
            }

            builder.productID = uberX.productID
            self.ridesClient.fetchRideRequestEstimate(parameters: builder.build(), completion: { rideEstimate, response in
                guard let rideEstimate = rideEstimate else {
                    // Handle error, unable to get an ride request estimate
                    return
                }
                builder.upfrontFare = rideEstimate.fare
               //uberCabExtimatedPriceList.addObjects(from: rideEstimate.fare)
                print("uberCabExtimatedPriceList:: ",uberCabExtimatedPriceList)
                self.ridesClient.requestRide(parameters: builder.build(), completion: { ride, response in
                    guard let ride = ride else {
                        // Handle error, unable to request ride
                        return
                    }
                    // Ride has been requested!
                })
            })
        }

    }

响应:

Status:401
Error: This endpoint requires at least one of the following scopes: request, request.delegate, request.delegate.tos_accept