403 Forbidden error when using REST Apis


#1

Hello,
I am using a guest auth to fetch the last tweet of a user in an android app. The problem that i am facing is that it seems to work initially but after some time, i keep getting 403 Forbidden code in the REST api call.

I am using the following code:

        Fabric.with(this, new Twitter(authConfig));


        TwitterCore.getInstance().logInGuest(new Callback() {
            @Override
            public void success(Result result) {
                final AppSession guestAppSession = (AppSession) result.data;

                TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
                twitterApiClient.getStatusesService().userTimeline(null, screen_name, 1, null, null, true, false, false, true, new Callback<List<Tweet>>() {
                    @Override
                    public void success(Result<List<Tweet>> listResult) {
//                        Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_LONG).show();
                        List<Tweet> tweets = listResult.data;
                        int i = tweets.size();
                        int count = 0;
                        while (count < i) {
                            Toast.makeText(MainActivity.this, tweets.get(count).text, Toast.LENGTH_LONG).show();
                            count++;
                        }
                        TwitterCore.getInstance().logOut();
                    }

                    @Override
                    public void failure(TwitterException e) {
                        Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG).show();
                    }
                });

            }

            @Override
            public void failure(TwitterException exception) {
                // unable to get an AppSession with guest auth
                Toast.makeText(MainActivity.this,"FAILURE_F",Toast.LENGTH_LONG).show();
            }
        });

Can somebody please help me out.

Warm Regards,
Gulati


#2

Maybe trying to pass the guestAppSession variable as parameter of getApiClient().

TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient(guestAppSession);

#3

@jahertor90 yup…that’s exactly what i did in the morning after posting the question…realized it a tad too late :frowning:
didn’t have any problem since then… :smile:
thanks anyways…


#4