I am trying to query Twitter on my android app and retrieve all the tweets related to the keyword "AgilebizKE" using retrofit. I am currently getting a 400 error code. After doing some research i have found that either my query parameters are wrong or my request isn't 'authorized'. However, i see no issues with my query parameters. Main Activity relevant code:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.twitter.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
tweetAPI tweetapi = retrofit.create(tweetAPI.class);
Call<List<tweet>> call = tweetapi.getTweets();
call.enqueue(new Callback<List<tweet>>() {
@Override
public void onResponse(Call<List<tweet>> call, Response<List<tweet>> response) {
if (!response.isSuccessful()) {
tweets_results.setText("code: " + response.code());
return;
}
List<tweet> tweets = response.body();
for (tweet tweet : tweets){
String content = "";
content+="Created at: "+tweet.getCreated_at()+"\n";
content+="Text: "+tweet.getText()+"\n";
content+="Retweets: "+tweet.getRetweet_count()+"\n";
content+="Favs: "+tweet.getFavorite_count()+"\n\n";
tweets_results.append(content);
}
}
@Override
public void onFailure(Call<List<tweet>> call, Throwable t) {
tweets_results.setText(t.getMessage());
}
});
Interface
public interface tweetAPI {
@GET("1.1/search/tweets.json?q=AgilebizKE")
Call<List<tweet>> getTweets();
}
Tweet pojo
ublic class tweet {
private String created_at;
private String text;
private String retweet_count;
private String favorite_count;
public String getCreated_at() {
return created_at;
}
public String getText() {
return text;
}
public String getRetweet_count() {
return retweet_count;
}
public String getFavorite_count() {
return favorite_count;
}
}