优步sdk集成错误

时间:2016-09-13 12:51:27

标签: android uber-api

我收到点击优步乘车请求小部件的消息。我在其他应用中使用了此link中的相同代码及其工作原理。我在这里做错了吗?我尝试了不同的client_id和server_token但得到了相同的结果。我想可能是拾取和放置位置可能太远,所以我编辑了附近的位置仍然得到相同的响应。

private static final String CLIENT_ID = "<MY_CLIENT_ID>";
private static final String REDIRECT_URI = "https://www.google.com";
private static final String SERVER_TOKEN = "<MY_SERVER_TOKEN>";

@Override
protected void onCreate(final Bundle savedInstanceState) {

	GPSTracker gpsTracker = new GPSTracker(this);

		PICKUP_LAT = gpsTracker.getLatitude();
		PICKUP_LONG = gpsTracker.getLongitude();


		System.out.println("picklatlng"+ " "+PICKUP_LAT + " " +PICKUP_LONG);

		LocationAddress locationAddress = new LocationAddress();
		locationAddress.getAddressFromLocation(PICKUP_LAT, PICKUP_LONG, getApplicationContext(), new GeocoderHandler());

		fetchdrop();



}

private void fetchdrop(){
		String url = getResources().getString(R.string.app_base_url)+ "&action=eventdetails&id=" + product_id;
		StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
				new Response.Listener<String>() {
					@Override
					public void onResponse(String response) {


						try {
							JSONObject jObj = new JSONObject(response);
							JSONArray jArray = jObj.getJSONArray("EventsList");
							for(int i=0;i<jArray.length();i++){
								JSONObject main = jArray.getJSONObject(i);

								drop_nick = main.getString("app_venue").trim();
								drop_addr = main.getString("app_location");
								drop_lat= Double.parseDouble(main.getString("app_lat"));
								drop_lng = Double.parseDouble(main.getString("app_lang"));
								System.out.println("UberSAM_dropdetails" + " "+ drop_nick +" "+drop_addr+" "+drop_lat+" "+drop_lng);
								uberConfig();
							}




						} catch (JSONException e) {
							// JSON error
							e.printStackTrace();
							Toast.makeText(Event_Details_Activity.this, "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
						}

					}
				}, new Response.ErrorListener() {
			@Override
			public void onErrorResponse(VolleyError error) {
				Toast.makeText(Event_Details_Activity.this, "VolleyError" + error.toString(), Toast.LENGTH_LONG).show();

			}
		}) {
            /*@Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();


                return params;
            }*/

		};

		RequestQueue requestQueue = Volley.newRequestQueue(Event_Details_Activity.this);
		requestQueue.add(stringRequest);


}

private void uberConfig() {

		SessionConfiguration configuration = new SessionConfiguration.Builder()
				.setRedirectUri(REDIRECT_URI)
				.setClientId(CLIENT_ID)
				.setServerToken(SERVER_TOKEN)
				.build();



		validateConfiguration(configuration);
		ServerTokenSession session = new ServerTokenSession(configuration);

		Log.e("EventDetailActivity", "session:" + session.getAuthenticator());


		System.out.println("UberSAM"+" "+"DROPOFF_ADDR:"+" "+drop_addr);
		System.out.println("UberSAM"+" "+"DROPOFF_NICK:"+" "+drop_nick);
		System.out.println("UberSAM"+" "+"DROPOFF_LAT:"+" "+drop_lat);
		System.out.println("UberSAM"+" "+"DROPOFF_LONG:"+" "+drop_lng);

		System.out.println("UberSAM"+" "+"PICKUP_ADDR:"+" "+PICKUP_ADDR);
		System.out.println("UberSAM"+" "+"PICKUP_NICK:"+" "+PICKUP_NICK);
		System.out.println("UberSAM"+" "+"PICKUP_LAT:"+" "+PICKUP_LAT);
		System.out.println("UberSAM"+" "+"PICKUP_LONG:"+" "+PICKUP_LONG);

		RideParameters rideParametersForProduct = new RideParameters.Builder()
				//.setProductId(UBERX_PRODUCT_ID)
				.setPickupLocation(PICKUP_LAT, PICKUP_LONG, PICKUP_NICK, PICKUP_ADDR)
				.setDropoffLocation(drop_lat, drop_lng, drop_nick, drop_addr)
				.build();

		RideRequestButton blackButton = (RideRequestButton) findViewById(R.id.uber_button_white_1);

		RideRequestActivityBehavior rideRequestActivityBehavior = new RideRequestActivityBehavior(this,
				WIDGET_REQUEST_CODE, configuration);



		blackButton.setRequestBehavior(rideRequestActivityBehavior);
		blackButton.setRideParameters(rideParametersForProduct);
		blackButton.setSession(session);
		blackButton.loadRideInformation();
		blackButton.setCallback(this);


}

private void validateConfiguration(SessionConfiguration configuration) {
		String nullError = "%s must not be null";
		String sampleError = "Please update your %s in the gradle.properties of the project before " +
				"using the Uber SDK Sample app. For a more secure storage location, " +
				"please investigate storing in your user home gradle.properties ";

		checkNotNull(configuration, String.format(nullError, "SessionConfiguration"));
		checkNotNull(configuration.getClientId(), String.format(nullError, "Client ID"));
		checkNotNull(configuration.getRedirectUri(), String.format(nullError, "Redirect URI"));
		checkNotNull(configuration.getServerToken(), String.format(nullError, "Server Token"));
		checkState(!configuration.getClientId().equals("insert_your_client_id_here"),
				String.format(sampleError, "Client ID"));
		checkState(!configuration.getRedirectUri().equals("insert_your_redirect_uri_here"),
				String.format(sampleError, "Redirect URI"));
		checkState(!configuration.getRedirectUri().equals("insert_your_server_token_here"),
				String.format(sampleError, "Server Token"));
}

enter image description here

1 个答案:

答案 0 :(得分:0)

该错误表示您用于对应用进行身份验证的优步帐户(实施小部件)已经从其他应用中启动。 The widget leverages the ride_widgets scope,但不包括访问其他应用中请求的行程。您可以结束当前存在的行程,然后重试。小部件应该按预期工作。

仅供参考,you can check out the all_trips范围可以看到您需要获得哪些额外的批准才能查看通过以下方式请求的优步帐户之旅优步应用程序或其他API集成。