タイトルが示すように、ボタンをクリックしてツイートを検索すると、400 件の Bad Request が返されます。以下は私のコードです:
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 を形成する方法。誰でも私を助けてくれませんか...