我想從Twitter獲得趨勢。任何人都可以幫助我請。我已經完成登錄使用login button
並獲得活動會議也現在麻煩是如何獲得趨勢散列標籤。android:如何從twitter獲取趨勢?
回答
https://dev.twitter.com/rest/reference/get/trends/place
例如請求:
https://api.twitter.com/1.1/trends/place.json?id=1
其中id是WOEID - 的雅虎凡位置
全球地球上的ID:1
印度:23424975
accesing twitterapi需要授權作爲標題。
public class ConstantsUtils {
public static final String URL_ROOT_TWITTER_API = "https://api.twitter.com";
public static final String URL_SEARCH = URL_ROOT_TWITTER_API + "/1.1/search/tweets.json?q=";
public static final String URL_AUTHENTICATION = URL_ROOT_TWITTER_API + "/oauth2/token";
public static final String URL_INDIA_TRENDING ="https://api.twitter.com/1.1/trends/place.json?id=23424977";
public static final String CONSUMER_KEY = "your key";
public static final String CONSUMER_SECRET = "your key";
}
用於獲取授權令牌
public static final String TAG = "TwitterUtils";
public static String appAuthentication() {
HttpURLConnection httpConnection = null;
OutputStream outputStream = null;
BufferedReader bufferedReader = null;
StringBuilder response = null;
try {
URL url = new URL(ConstantsUtils.URL_AUTHENTICATION);
httpConnection = (HttpURLConnection) url.openConnection();
httpConnection.setRequestMethod("POST");
httpConnection.setDoOutput(true);
httpConnection.setDoInput(true);
String accessCredential = ConstantsUtils.CONSUMER_KEY + ":"
+ ConstantsUtils.CONSUMER_SECRET;
String authorization = "Basic "
+ Base64.encodeToString(accessCredential.getBytes(),
Base64.NO_WRAP);
String param = "grant_type=client_credentials";
httpConnection.addRequestProperty("Authorization", authorization);
httpConnection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
httpConnection.connect();
outputStream = httpConnection.getOutputStream();
outputStream.write(param.getBytes());
outputStream.flush();
outputStream.close();
// int statusCode = httpConnection.getResponseCode();
// String reason =httpConnection.getResponseMessage();
bufferedReader = new BufferedReader(new InputStreamReader(
httpConnection.getInputStream()));
String line;
response = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
response.append(line);
}
Log.d(TAG,
"POST response code: "
+ String.valueOf(httpConnection.getResponseCode()));
Log.d(TAG, "JSON response: " + response.toString());
} catch (Exception e) {
Log.e(TAG, "POST error: " + Log.getStackTraceString(e));
} finally {
if (httpConnection != null) {
httpConnection.disconnect();
}
}
return response.toString();
}
爲了得到趨勢。
public static String getTimelineForSearchTerm(String twitt_url,
Context context) {
HttpURLConnection httpConnection = null;
BufferedReader bufferedReader = null;
StringBuilder response = new StringBuilder();
try {
URL url = new URL(ConstantsUtils.URL_INDIA_TRENDING);
httpConnection = (HttpURLConnection) url.openConnection();
httpConnection.setRequestMethod("GET");
String jsonString = appAuthentication();
JSONObject jsonObjectDocument = new JSONObject(jsonString);
String token = jsonObjectDocument.getString("token_type") + " "
+ jsonObjectDocument.getString("access_token");
httpConnection.setRequestProperty("Authorization", token);
httpConnection.setRequestProperty("Authorization", token);
httpConnection.setRequestProperty("Content-Type",
"application/json");
httpConnection.connect();
bufferedReader = new BufferedReader(new InputStreamReader(
httpConnection.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
response.append(line);
}
Log.d(TAG,
"GET response code: "
+ String.valueOf(httpConnection
.getResponseCode()));
Log.d(TAG, "JSON response: " + response.toString());
} catch (Exception e) {
Log.e(TAG, "GET error: " + Log.getStackTraceString(e));
} finally {
if (httpConnection != null) {
httpConnection.disconnect();
}
}
}
return response.toString();
}
併爲獲取雅虎WOEID只是通過您的位置的經緯度。
http://where.yahooapis.com/v1/places.q('"
+ latitude
+ ","
+ longitude
+ "')?appid=yourappid&format=json"
請仔細閱讀有關獲取授權請求,並得到授權頭
我知道這是網址,但如何調用它?點擊它給我這個錯誤「錯誤」: [ { 「code」:215, 「message」:「Bad Authentication data。」 } ] –
可以請你解釋一下,我可以如何附加訪問令牌或其他東西,因爲我想在應用程序中調用它我有userid和訪問令牌..所以請告訴我如何確切地調用它請 –
嘿我有更新了我的答案。請現在嘗試 –
- 1. 如何從Twitter獲取每日趨勢?
- 2. 如何使用PHP獲取Twitter趨勢
- 3. 如何從twitter獲取關於特定位置的趨勢
- 4. 獲取國家頂級Twitter趨勢
- 5. 使用tmhoauth獲取twitter趨勢woooooo
- 6. 無法使用PHP獲取Twitter趨勢
- 7. PHP從MySQL表獲取數據,如Twitter趨勢
- 8. PHP Twitter的趨勢
- 9. 如何從Twitter API和趨勢線獲得粉絲數
- 10. 如何解析Twitter趨勢Json響應
- 11. 如何使用auh與Twitter趨勢
- 12. 如何獲取推特趨勢列表
- 13. Twitter的API - 趨勢/地方
- 14. PHP JSON Twitter的趨勢
- 15. Twitter的履帶趨勢
- 16. Twitter類別的趨勢
- 17. Twitter的API趨勢迅速
- 18. 從原始數據獲取趨勢
- 19. 什麼是Twitter API獲取趨勢限制?
- 20. 的Python:獲取Twitter的趨勢tweepy,並解析JSON
- 21. Twitter API - 使用Jquery和Json獲取WOEID特定的趨勢詞?
- 22. 獲取url twitter的趨勢返回總是爲空
- 23. 如何從Google Trends趨勢圖上獲取數值
- 24. 檢查從twitter提取的趨勢的語言
- 25. Twitter的趨勢:如何獲取前100名最常用的單詞?
- 26. Twitter流式傳輸:根據國家/地區獲取Twitter上的趨勢
- 27. 使用twitter api獲取阿拉伯語趨勢,我得到符號而不是實際的趨勢?
- 28. Twitter API GET趨勢404錯誤
- 29. 多字的Twitter趨勢主題
- 30. 用php/mysql發佈Twitter風格趨勢
顯示你的代碼! –