Combining 2 api calls into 1

android

#1

hello ,
so i am trying call around 100 timelines in my app. but i am reaching the api limit so i have to request 100 timelines with different SearchTimelines query . the problem i am having is i am getting result from both the calls but i dont know how combine them as 1 .because i have to insert them in listadapter as shown below . somehow i need to combine both the Searchtime result into 1.so any help would be apreciated

this is my code :

 SearchTimeline searchTimeline = null;
        searchTimeline = new SearchTimeline.Builder()
                .query("from:GosuGamers OR from:follow2GD OR from:MSSDota OR from:BTSGoDz OR from:PyrionFlax OR from:StatsManBruno OR from:EvilGeniuses")
                .build();



        SearchTimeline searchTimeline2 = null;
        searchTimeline2 = new SearchTimeline.Builder()
                .query("from:PurgeGamers OR from:Fnggshka OR from:Mushi_Chai OR from:team_empire OR from:ixmike88 OR from:dota2reddit OR from:QOdota")
                .build();





        TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this)
                .setTimeline()
                .build();


        setListAdapter(adapter);

thanks


#2

Hi @rominv13,

One of the options can be, to use TwitterKit to, first, interact with the REST API and make these two different searches. Then get their Tweets, merge them in a list of Tweet objects, and then use FixedTweetTimeline to render that list to the UI.

Here’s how you interact with REST API with TwitterKit : https://docs.fabric.io/android/twitter/access-rest-api.html

And here’s how you use FixedTweetTimeline : https://docs.fabric.io/android/twitter/show-timelines.html#timeline-builders

Let us know if that helps?


#3

hello ,
i tried to use your method but i am getting 403 forbidden
here is my code : "TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
SearchService search = twitterApiClient.getSearchService();

    search.tweets("from:PurgeGamers OR from:Fnggshka", null, null, null, null, null, null, null, null, null, new Callback<Search>() {
        @Override
        public void success(Result<Search> result) {
            list = result.data.tweets;
            FixedTweetTimeline timeline = new FixedTweetTimeline.Builder()
                    .setTweets(list)
                    .build();

            TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(MainActivity.this)
                    .setTimeline(timeline)
                    .build();

            setListAdapter(adapter);
        }"

and here is the error : “W/System.err: com.twitter.sdk.android.core.TwitterApiException: 403 Forbidden
06-17 16:02:01.031 22362-22362/com.example.romin.twitterexample W/System.err: at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:383)
06-17 16:02:01.031 22362-22362/com.example.romin.twitterexample W/System.err: at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
06-17 16:02:01.031 22362-22362/com.example.romin.twitterexample W/System.err: at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
06-17 16:02:01.031 22362-22362/com.example.romin.twitterexample W/System.err: at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
06-17 16:02:01.031 22362-22362/com.example.romin.twitterexample W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
06-17 16:02:01.031 22362-22362/com.example.romin.twitterexample W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-17 16:02:01.031 22362-22362/com.example.romin.twitterexample W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
06-17 16:02:01.031 22362-22362/com.example.romin.twitterexample W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
06-17 16:02:01.031 22362-22362/com.example.romin.twitterexample W/System.err: at java.lang.Thread.run(Thread.java:818)
06-17 16:02:02.729 22362-22401/com.example.romin.twitterexample W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
” can anyone help on why am i getting this error


#4

Have you authenticated your request?

That error code means you’re trying to access a protected resource, without authentication.

As the document suggests, you need to either have guest authentication, or user authentication, before making the REST call.


#5

i am getting this error only for this query . other query i can run properly and i took the authentication