gpt4 book ai didi

android - 基本网络.performRequest : Unexpected response code 401

转载 作者:行者123 更新时间:2023-11-30 01:30:06 27 4
gpt4 key购买 nike

我正在尝试从优步获取访问 token (我能够收到请求代码)。但是每当我尝试调用调用响应时总是显示错误

BasicNetwork.performRequest: Unexpected response code 401 for https://login.uber.com/oauth/v2/token?code=6DAhQDdKQhE3ZD9aTekXRAW4SZDjcN&grant_type=authorization_code

这是文档显示如何获取 access_token 的内容

parameters = {
'redirect_uri': 'INSERT_ROUTE_TO_STEP_TWO',
'code': request.args.get('code'),
'grant_type': 'authorization_code',}

response = requests.post(
'https://login.uber.com/oauth/token',
auth=(
'INSERT_CLIENT_ID',
'INSERT_CLIENT_SECRET',
),
data=parameters,)
access_token = response.json().get('access_token')

这就是我尝试获取 access_code 的方式

String uber = new Uri.Builder()
.scheme("https")
.authority("login.uber.com")
.path("oauth/v2/token")
//.appendQueryParameter("server_token", "P9CQP52XZfA6zGPts8ZCGT2buhJoz80gTAroKUd")
.appendQueryParameter("code", code)
.appendQueryParameter("grant_type","authorization_code")
.build().toString();
//final String requestBody = "grant_type=authorization_code";
JsonObjectRequest jsonObjectRequest = jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, uber, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
try {
progressActivity.showContent();
SharedPref.saveUberToken(getApplicationContext(), jsonObject.getString("access_token"));
SharedPref.saveUberRefreshToken(getApplicationContext(),jsonObject.getString("refresh_token"));
OathUser();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {

}
}){
/**
* Passing some request headers *
* */
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
headers.put("client_id", "IEXY6JG6y1AVqtlVZtzDOqcn3EYIBR6");
headers.put("client_secret", "7It74u9pb10ogZbvFro3EO3QNKm9Zscq3cogPVN");
return headers;
}
};

谁有解决办法...我认为我的代码与此不匹配

auth=(
'INSERT_CLIENT_ID',
'INSERT_CLIENT_SECRET',
)

最佳答案

下面的代码可能会帮助您了解一些想法。将此更改为您方便的代码,下面的代码用于发布请求。

            URL url = new URL("https://xx.com/yy/");
HttpsURLConnection urlConnection =
(HttpsURLConnection) url.openConnection();


String publicKey = "test_key:pass";
String encodedString = Base64.encodeToString(publicKey.getBytes(), Base64.NO_WRAP);
String basicAuth = "Basic ".concat(encodedString));


//setting header for authentication purpose, should use authorization as keyword if you change this it won't work anymore
urlConnection.setRequestProperty("Authorization", basicAuth);

//setting other url options
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setConnectTimeout(15000);
urlConnection.setReadTimeout(15000);
urlConnection.setRequestMethod("POST");

关于android - 基本网络.performRequest : Unexpected response code 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35863403/

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