gpt4 book ai didi

android - 使用 android volley 获取 Instagram 访问 token

转载 作者:太空狗 更新时间:2023-10-29 16:35:49 27 4
gpt4 key购买 nike

我使用此代码向 instagram 发布请求并获取访问 token 。

URL url = new URL(tokenURLString);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setRequestMethod("POST");
httpsURLConnection.setDoInput(true);
httpsURLConnection.setDoOutput(true);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpsURLConnection.getOutputStream());
outputStreamWriter.write("client_id="+CI +
"&client_secret="+ CS +
"&grant_type=authorization_code" +
"&redirect_uri="+CALLBACK_URL+
"&code=" + requestToken);
outputStreamWriter.flush();
JSONObject jsonObject = new JSONObject(StreamToString.get(httpsURLConnection.getInputStream()));

我如何使用 android volley 做到这一点?

最佳答案

我只是自己实际实现了这个。这是我使用的代码。

    public void requestAccessToken(final String code) {
StringRequest request = new StringRequest(Request.Method.POST, TOKENURL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("Success Response = ", response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error Response = ", error.toString());
}
}) {
@Override
protected Map<String,String> getParams(){
Map<String, String> params = new HashMap<String, String>();
params.put("client_id", CLIENTID);
params.put("client_secret", CLIENTSECRET);
params.put("grant_type", "authorization_code");
params.put("redirect_uri", REDIRECTURL);
params.put("code", code);
return params;
}
};

Volley.newRequestQueue(this).add(request);
}

关于android - 使用 android volley 获取 Instagram 访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29060453/

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