Tweets not showing up


#1

Twitter: API call failure.
com.twitter.sdk.android.core.TwitterApiException: 403 Forbidden
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:383)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

Not sure what the issue is. I have triple checked that my keys are correct. I have even tried resetting them. I have not been able to get the tweets to show up once (I am trying to do a user timeline). I just keep getting this error. When I use fabric to check that the code is right, it doesn’t tell me to change anything. Really not sure what the issue is. Let me know what other info is needed and I will provide it. Thanks for the help!


#2

Hey @arsfcgunners,

Can you share a bit more of the code that you’re using? Also, you mentioned triple checking the keys - are there any conflicting Twitter Consumer key’s? For example, one in your AndroidManifest.xml or build.gradle and another one when you initialize Fabric?


#3

@bonnell ok, so I have gotten the error to go away. Now I am getting no errors, but the tweets are not showing up. It just is showing the “no tweets” textview. Here is my code. I am very knew to Android development so I could be doing something stupid idk.

In the main activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig), new Crashlytics());

My fragment:
public class NewsFragment extends ListFragment implements SwipeRefreshLayout.OnRefreshListener {
View rootView;
SwipeRefreshLayout swipeLayout;
TweetTimelineListAdapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SearchTimeline searchTimeline = new SearchTimeline.Builder()
            .query("#fail")
            .build();
    adapter = new TweetTimelineListAdapter.Builder(getActivity())
            .setTimeline(searchTimeline)
            .build();
    setListAdapter(adapter);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.newsfragment, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_refresh) {
        updateFeed();
        return true;
    }
    return super.onOptionsItemSelected(item);
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_news, container, false);

    swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.fragment_news);

    swipeLayout.setOnRefreshListener(this);
    return rootView;
}

@Override
public void onRefresh() {
   updateFeed();
}

public void updateFeed(){
    swipeLayout.setRefreshing(true);
    adapter.refresh(new Callback<TimelineResult<Tweet>>() {
        @Override
        public void success(Result<TimelineResult<Tweet>> result) {
            swipeLayout.setRefreshing(false);
        }

        @Override
        public void failure(TwitterException exception) {
            Snackbar.make(getView(), "The news could not be refreshed. Please try again soon!", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}

}

Fragment XML:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height=“match_parent"
tools:context=“com.swissymania.android.nextspaceflight.NewsFragment"
android:id=”@+id/fragment_news”>

<TextView android:id="@id/android:empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal|center_vertical"
    android:text="No Tweets"/>

<ListView android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:divider="#e1e8ed"
    android:dividerHeight="1dp"
    android:drawSelectorOnTop="false"/>

</android.support.v4.widget.SwipeRefreshLayout>