正如我的标题所说,当我点击一个按钮搜索推文时,我收到了 400 个错误请求。下面是我的代码:
String webUrl = "https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&since_id=*****&max_id=*****&result_type=mixed&count=4";
public static String getSearchDetails(String webUrl)
throws ClientProtocolException, IOException {
StringBuilder builder = new StringBuilder();
try {
URI url = new URI(webUrl);
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
return null;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
String responseWS = builder.toString();
return responseWS;
}
400 Bad Request 是由于用户未通过身份验证。如何以这样的方式形成 url,用户将使用 Consumer Key、Consumer Secret 进行身份验证。谁能帮帮我吗...