我想實現Twitter搜索API V1.1無記名代碼返回HTTP 400錯誤的Twitter搜索API V1.1
請糾正我,如果我錯了。 我執行下面提到步驟:
Step 1) Created an App in Twitter.
So I got the TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRETCODE.
Step 2) I encoded the concatenation of the above keys separated by ":" with the base UTF-8.
Step3) Get the bearer token with the above generated code.
Step4) Use the bearer code to get the Tweets on the relevance of a keyword.
我被困在步驟3,
在那裏我得到了響應,::
Server returned HTTP response code: 400 for URL: https://api.twitter.com/oauth2/token
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at com.tcs.crm.socialCRM.action.TwitterIntegration.requestBearerToken(TwitterIntegration.java:74)
at com.tcs.crm.socialCRM.action.TwitterIntegration.getStatusSearch(TwitterIntegration.java:27)
at com.tcs.crm.socialCRM.action.TwitterIntegration.main(TwitterIntegration.java:103)
我的代碼::
HttpsURLConnection connection = null;
PrintWriter outWriter = null;
BufferedReader serverResponse = null;
try
{
URL url = new URL(endPointUrl);
connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Host", "api.twitter.com");
connection.setRequestProperty("User-Agent", "Search Tweets");
connection.setRequestProperty("Authorization", "Basic " + encodedCredentials);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
connection.setRequestProperty("Content-Length", "29");
connection.setUseCaches(false);
connection.setDoOutput(true);
logger.info("Point 1");
//CREATE A WRITER FOR OUTPUT
outWriter = new PrintWriter(connection.getOutputStream());
logger.info("Point 2");
//SEND PARAMETERS
outWriter.println("grant_type=client_credentials");
outWriter.flush();
outWriter.close();
logger.info("Point 3");
//RESPONSE STREAM
serverResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
JSONObject obj = (JSONObject)JSONValue.parse(serverResponse);
logger.info("The return string is "+obj.toString());
return obj.toString();
請讓我知道如何解決此問題。
+ 1 。將通過鏈接。謝了哥們 –