Android extension example


#1

I am looking for an example on how to implement the extension functionality described at https://dev.twitter.com/twitter-kit/android/api

I would like to get a list of users friends using the “/1.1/friends/ids.json”


How to get all followers/friends with the cursor parameter in Android
#2

Using the example listed, we can modify it to work with the “/1.1/friends/ids.json” link like so:

import com.google.gson.annotations.SerializedName;
import retrofit.http.GET;
import retrofit.http.Query;

public class MyTwitterApiClient extends TwitterApiClient {
    public MyTwitterApiClient(Session session) {
        super(session);
    }

    /**
     * Provide FriendsService with ids
     */
    public FriendsService getFriendsService() {
        return getService(FriendsService.class);
    }

    public interface FriendsService {
        @GET("/1.1/friends/ids.json")
        void ids(@Query("user_id") Long userId,
                 @Query("screen_name") String screenName,
                 @Query("cursor") Long cursor,
                 @Query("stringify_ids") Boolean stringifyIds,
                 @Query("count") Integer count,
                 Callback<Ids> cb);

        void idsByUserId(@Query("user_id") Long userId, 
                         Callback<Ids> cb);
    }

    public class Ids {
        @SerializedName("previous_cursor")
        public final Long previousCursor;

        @SerializedName("ids")
        public final Long[] ids;

        @SerializedName("next_cursor")
        public final Long nextCursor;


        public Ids(Long previousCursor, Long[] ids, Long nextCursor) {
            this.previousCursor = previousCursor;
            this.ids = ids;
            this.nextCursor = nextCursor;
        }
    }
}

This can then be used like so:

MyTwitterApiClient client = new MyTwitterApiClient(Twitter.getSessionManager().getActiveSession());
        client.getFriendsService().idsByUserId(id, new Callback<MyTwitterApiClient.Ids>() {
            @Override
            public void success(Result<MyTwitterApiClient.Ids> result) {
                //success
            }

            @Override
            public void failure(TwitterException exception) {
                //failure
            }
        });
    }

#3

Thank you very much! This is extremely helpful!


#4