在您的自定义关注按钮点击事件中使用以下代码 -
TwitterFollow apiClient = new TwitterFollow(session);
apiClient.getFollowService().create("Screen_Name_of_person_to_follow", null, true, new Callback<User>() {
@Override
public void success(Result<User> result) {
Toast.makeText(MainActivity.this, "Thanks for following!", Toast.LENGTH_SHORT).show();
}
@Override
public void failure(TwitterException e) {
Toast.makeText(MainActivity.this, "Error following", Toast.LENGTH_SHORT).show();
}
});
并将 TwitterFollow 类创建为 -
public class TwitterFollow extends TwitterApiClient {
public TwitterFollow(TwitterSession session) {
super(session);
}
public FollowService getFollowService() {
return getService(FollowService.class);
}
public interface FollowService {
@POST("/1.1/friendships/create.json")
public void create(@Query("screen_name") String screen_name, @Query("user_id") String user_id, @Query("follow") boolean follow, Callback<User> cb);
}
}