【发布时间】:2014-12-19 08:03:27
【问题描述】:
我要为每个用户编写一个有超过 50 个请求的应用程序。我应该为每个经过身份验证的用户获取访问令牌吗? 以及如何使用 java 来实现?我获取 API 但如何获取访问令牌?
class GetRequestAsyncTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... uri) {
DefaultHttpClient http_client = new DefaultHttpClient();
HttpResponse response;
String respondString;
try {
response = http_client.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
respondString = out.toString();
out.close();
Log.w("FLAG!", "Data downloaded:"+respondString);
return respondString;
} else {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
Log.e("ClientProtocolException GetTask", e.toString());
return "";
} catch (IOException e) {
Log.e("IOException GetTask", e.toString());
return "";
}
}
【问题讨论】:
-
您想要新的 oauth 访问令牌?或者什么..请清楚