Getting banned when using Twitter Fabric to get user_timeline

I am trying to implement Fabric to get a list of the last 5 tweets from the user. He worked perfectly for several hours, and then he stopped working. I would like to do this without a user logging in, and as far as I can tell, the API allows guest logins to read tweets, but maybe this has a bigger impact on speed limits?

@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());
    TwitterCore.getInstance().logInGuest(new Callback() {
        @Override
        public void success(Result result) {
            AppSession session = (AppSession) result.data;
            getTweets();
        }

        @Override
        public void failure(TwitterException exception) {
            // unable to get an AppSession with guest auth
        }
    });
}

    public void getTweets() {

    TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
    StatusesService statusesService = twitterApiClient.getStatusesService();


    statusesService.userTimeline([USERID], null, 5, null, null, null, true, null, false, new Callback<List<Tweet>>() {
        @Override
        public void success(Result <List<Tweet>> result) {

            for(Tweet Tweet : result.data) {
                tweetList.add(Tweet.text);
            }
            createListView();
        }
        public void failure(TwitterException exception) {
            Log.e("Failure", exception.toString());
            exception.printStackTrace();
        }
    });
}

When I don't get 403, everything works fine and my list is populated.

Now, is it possible that there is something wrong with my code that fixes me in the black list? Otherwise; do I need a user to log in to show them 5 tweets? Or should I implement some kind of server cache?

Thanks for the tips / help.

+4
3

, . , logInGuest, getApiClient. , :

private TweetViewFetchAdapter adapter;
...
adapter = new TweetViewFetchAdapter<CompactTweetView>(getActivity());
...
TwitterCore.getInstance().logInGuest( new Callback<AppSession>() {
    @Override
    public void success(Result<AppSession> appSessionResult) {
        AppSession session = appSessionResult.data;
        TwitterApiClient twitterApiClient =  TwitterCore.getInstance().getApiClient(session);
        twitterApiClient.getStatusesService().userTimeline(null, "RadioOkinawa864", 10, null, null, false, false, false, true, new Callback<List<Tweet>>() {
            @Override
            public void success(Result<List<Tweet>> listResult) {
                adapter.setTweets(listResult.data);
            }

            @Override
            public void failure(TwitterException e) {
                Toast.makeText(getActivity().getApplicationContext(), "Could not retrieve tweets", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        });
    }

    @Override
    public void failure(TwitterException e) {
        Toast.makeText(getActivity().getApplicationContext(), "Could not get guest Twitter session", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
});
+5

logInGuest , AppSessions . TwitterExceptions AppSession. ,

TwitterApiClient twitterApiClient =  TwitterCore.getInstance().getApiClient(guestAppSession);
twitterApiClient.getSearchService().tweets("#fabric", null, null, null, null, 50, null, null, null, true, new Callback<Search>() {
    @Override
    public void success(Result<Search> result) {
        // use result tweets
    }

    @Override
    public void failure(TwitterException exception) {
        final TwitterApiException apiException = (TwitterApiException) exception;
        final int errorCode = apiException.getErrorCode();
        if (errorCode == TwitterApiConstants.Errors.APP_AUTH_ERROR_CODE || errorCode == TwitterApiConstants.Errors.GUEST_AUTH_ERROR_CODE) {
            // request new guest AppSession (i.e. logInGuest)
            // optionally retry
        }
    }
});

, AppSessions API, . , Tweet AppSession. . . TwitterKit Android REST API docs.

, TweetUtils.loadTweet TweetUtils.loadTweets TweetUi Twitter, , logInGuest.

+3

api 403 Your app may not allow guest auth. Please talk to us regarding upgrading your consumer key.

, .

0

All Articles