gpt4 book ai didi

android - Uber 在 android 中提供了无效的 OAuth 2.0 凭据 Uber 身份验证

转载 作者:太空宇宙 更新时间:2023-11-03 10:37:35 27 4
gpt4 key购买 nike

我正在集成优步乘车请求 API。我成功验证了 uber 帐户。我可以从 uber api 获取用户历史记录和用户配置文件,但我没有获取 v1.2/requests/estimate。但是当我请求乘车时。使用下面的代码......

我收到回复了。

{"message":"Invalid OAuth 2.0 credentials provided.","code":"unauthorized"}

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

}

最佳答案

这可能是因为您的 header 中的“bearer”和 token 值之间没有提供空格。 httpPost.setHeader("Authorization","Bearer"+token);

必须是Authorization: Bearer <mytoken>

更新

您正在将数据值设置为名称-值对。如果内容类型是 json,则必须设置 json。检查这个答案:How to send POST request in JSON using HTTPClient?

你必须设置:

 JSONObject holder = getJsonObjectFromMap(params);

//passes the results to a string builder/entity
StringEntity se = new StringEntity(holder.toString());

//sets the post request as the resulting string
httpost.setEntity(se);

关于android - Uber 在 android 中提供了无效的 OAuth 2.0 凭据 Uber 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40945491/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com