Im整合超級通行證請求api。我成功驗證了超級帳戶。我可以從uber api獲取用戶歷史記錄和用戶資料,但我沒有獲得v1.2/requests/estimate。但是當我請求騎車時。使用下面的代碼...Uber無效的OAuth 2.0憑據提供優步認證在Android
我得到的迴應。
{ 「消息」: 「2.0憑證提供無效的OAuth。」, 「代碼」: 「未授權」}
public JSONObject getFareid(String address,String product_id,floatstart_latitude,float start_longitude,float end_latitude,floatend_longitude,String token,String scope) {
try {
httpClient = new DefaultHttpClient();
httpPost = new HttpPost(address);
params.add(new BasicNameValuePair("product_id", product_id));
params.add(new BasicNameValuePair("start_latitude", "17.456f"));
params.add(new BasicNameValuePair("start_longitude", "78.3755f"));
params.add(new BasicNameValuePair("end_latitude", "17.3853f"));
params.add(new BasicNameValuePair("end_longitude","78.404f"));
params.add(new BasicNameValuePair("Authorization","Bearer"+token));
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("Accept-Language", "en_US");
httpPost.setHeader("Authorization","Bearer"+token);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "n");
}
is.close();
json = sb.toString();
Log.e("JSONStr", json);
} catch (Exception e) {
e.getMessage();
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// Parse the String to a JSON Object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// Return JSON String
return jObj;
}
}
爲什麼你正在做的所有的呼叫手動尤伯杯爲同一提供SDK在那裏你可以找到估計乘坐方法也會降低你的工作太 –
我認爲'Authorization'只是一個頭部,而不是POST參數。然後再次,我沒有閱讀API文檔。除此之外,我建議你看看改進庫(或實際的優步Android SDK) –
@ cricket_007優步sdk做他們正在使用改進 –