com.twitter.sdk.android.core.models.User Java Examples

The following examples show how to use com.twitter.sdk.android.core.models.User. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TwitterServiceImpl.java    From twittererer with Apache License 2.0 6 votes vote down vote up
public Observable<com.zedeff.twittererer.models.User> getMyDetails() {
    return Observable.create(subscriber -> {
        Callback<User> callback = new Callback<User>() {
            @Override
            public void success(Result<User> result) {
                Log.i(TAG, "Got your details, pal!");
                subscriber.onNext(new com.zedeff.twittererer.models.User(result.data.name, result.data.screenName, result.data.profileImageUrl));
            }

            @Override
            public void failure(TwitterException e) {
                Log.e(TAG, e.getMessage(), e);
                subscriber.onError(e);
            }
        };

        getService(UserService.class).show(TwitterCore.getInstance().getSessionManager().getActiveSession().getUserId()).enqueue(callback);
    });
}
 
Example #2
Source File: TwitterSignUpActivity.java    From socialmediasignup with MIT License 6 votes vote down vote up
private void handleSuccess(final TwitterSession session) {
    TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
    AccountService accountService = twitterApiClient.getAccountService();
    call = accountService.verifyCredentials(false, true, true);
    call.enqueue(new Callback<User>() {
        @Override
        public void success(Result<User> userResult) {
            SocialMediaUser user = new SocialMediaUser();
            User data = userResult.data;
            user.setUserId(String.valueOf(data.getId()));
            user.setAccessToken(session.getAuthToken().token);
            user.setProfilePictureUrl(String.format(PROFILE_PIC_URL, data.screenName));
            user.setEmail(data.email != null ? data.email : "");
            user.setFullName(data.name);
            user.setUsername(data.screenName);
            user.setPageLink(String.format(PAGE_LINK, data.screenName));
            handleSuccess(SocialMediaSignUp.SocialMediaType.TWITTER, user);
        }

        public void failure(TwitterException error) {
            handleError(error);
        }
    });
}
 
Example #3
Source File: LoginMaster.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
private void fetchTwitterUserData(final IOperationFinishWithDataCallback profileFetched) {
    TwitterSession session =
            Twitter.getSessionManager().getActiveSession();
    Twitter.getApiClient(session).getAccountService()
            .verifyCredentials(true, false, new Callback<User>() {
                @Override
                public void success(Result<User> userResult) {
                    User user = userResult.data;
                    userProfile = new UserProfile();
                    userProfile.setName(user.screenName);
                    String profileImage = user.profileImageUrlHttps;
                    profileImage = profileImage.replace("_normal", "");
                    userProfile.setProfileImageUrl(profileImage);
                    profileFetched.operationFinished(userProfile);
                }

                @Override
                public void failure(TwitterException e) {

                }
            });
}
 
Example #4
Source File: UniqueTweetActivity.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.tweetui_fragment_unique_tweet, container,
            false);

    final LinearLayout tweetRegion = v.findViewById(R.id.tweet_region);

    // Tweet object already present, construct a TweetView
    final Tweet knownTweet = new TweetBuilder()
            .setId(3L)
            .setUser(new UserBuilder()
                            .setId(User.INVALID_ID)
                            .setName("name")
                            .setScreenName("namename")
                            .setVerified(false)
                            .build()
            )
            .setText("Preloaded text of a Tweet that couldn't be loaded.")
            .setCreatedAt("Wed Jun 06 20:07:10 +0000 2012")
            .build();
    final TweetView knownTweetView = new TweetView(getActivity(), knownTweet);
    tweetRegion.addView(knownTweetView);

    return v;
}
 
Example #5
Source File: TestFixtures.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
static Tweet createPhotoTweet(long id, User user, String text, String timestamp,
        String photoUrlHttps) {
    final MediaEntity photoEntity = new MediaEntity("", "", "", 0, 0, 0L, null, null,
            photoUrlHttps, createMediaEntitySizes(100, 100), 0L, null, "photo", null, "");
    final ArrayList<MediaEntity> mediaEntities = new ArrayList<>();
    mediaEntities.add(photoEntity);
    final TweetEntities entities = new TweetEntities(null, null, mediaEntities, null, null);
    return new TweetBuilder()
            .setId(id)
            .setUser(user)
            .setText(text)
            .setCreatedAt(timestamp)
            .setEntities(entities)
            .setExtendedEntities(entities)
            .build();
}
 
Example #6
Source File: TestFixtures.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
static Tweet createMultiplePhotosTweet(int count, long id, User user, String text,
                                              String timestamp, String photoUrlHttps) {
    final ArrayList<MediaEntity> mediaEntities = new ArrayList<>();
    for (int x = 0; x < count; x++) {
        final MediaEntity photoEntity = new MediaEntity("", "", "", 0, 0, 0L, null, null,
                photoUrlHttps, createMediaEntitySizes(100, 100), 0L, null, "photo", null, "");
        mediaEntities.add(photoEntity);
    }
    final TweetEntities entities = new TweetEntities(null, null, mediaEntities, null, null);
    return new TweetBuilder()
            .setId(id)
            .setUser(user)
            .setText(text)
            .setCreatedAt(timestamp)
            .setEntities(entities)
            .setExtendedEntities(entities)
            .build();
}
 
Example #7
Source File: TwitterAuthClientTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequestEmail_withFailure() {
    final IOException networkException = new IOException("Network failure");
    final Call<User> call = Calls.failure(networkException);
    setupMockAccountService(call);

    authClient.requestEmail(mock(TwitterSession.class), new Callback<String>() {
        @Override
        public void success(Result<String> result) {
            fail("Expected Callback#failure to be called");
        }

        @Override
        public void failure(TwitterException exception) {
            assertEquals(exception.getCause(), networkException);
        }
    });
}
 
Example #8
Source File: TwitterAuthClientTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequestEmail_withSuccess() {
    final User user = new UserBuilder().setEmail(TEST_EMAIL).build();
    final Call<User> call = Calls.response(user);
    setupMockAccountService(call);

    authClient.requestEmail(mock(TwitterSession.class), new Callback<String>() {
        @Override
        public void success(Result<String> result) {
            assertEquals(TEST_EMAIL, result.data);
        }

        @Override
        public void failure(TwitterException exception) {
            fail("Expected Callback#success to be called");
        }
    });
}
 
Example #9
Source File: UserUtils.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
public static String getProfileImageUrlHttps(User user, AvatarSize size) {
    if (user != null && user.profileImageUrlHttps != null) {
        final String url = user.profileImageUrlHttps;
        if (size == null || url == null) {
            return url;
        }

        switch (size) {
            case NORMAL:
            case BIGGER:
            case MINI:
            case ORIGINAL:
            case REASONABLY_SMALL:
                return url
                        .replace(AvatarSize.NORMAL.getSuffix(), size.getSuffix());
            default:
                return url;
        }
    } else {
        return null;
    }
}
 
Example #10
Source File: TwitterAuthClient.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
/**
 * Requests the user's email address.
 *
 * @param session the user session
 * @param callback The callback interface to invoke when the request completes. If the user
 *                 denies access to the email address, or the email address is not available,
 *                 an error is returned.
 * @throws java.lang.IllegalArgumentException if session or callback are null.
 */
public void requestEmail(TwitterSession session, final Callback<String> callback) {
    final Call<User> verifyRequest = twitterCore.getApiClient(session).getAccountService()
            .verifyCredentials(false, false, true);

    verifyRequest.enqueue(new Callback<User>() {
        @Override
        public void success(Result<User> result) {
            callback.success(new Result<>(result.data.email, null));
        }

        @Override
        public void failure(TwitterException exception) {
            callback.failure(exception);
        }
    });
}
 
Example #11
Source File: BasicTimelineFilterTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldFilterTweet_withUserMatch() {
    final User user = new UserBuilder().setScreenName("EricFrohnhoefer").build();
    final Tweet tweet = new TweetBuilder().setText("").setUser(user).build();

    assertTrue(basicTimelineFilter.shouldFilterTweet(tweet));
}
 
Example #12
Source File: ComposerController.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
void setProfilePhoto() {
    dependencyProvider.getApiClient(session).getAccountService()
            .verifyCredentials(false, true, false).enqueue(new Callback<User>() {
                @Override
                public void success(Result<User> result) {
                    composerView.setProfilePhotoView(result.data);
                }

                @Override
                public void failure(TwitterException exception) {
                    // show placeholder background color
                    composerView.setProfilePhotoView(null);
                }
            });
}
 
Example #13
Source File: ComposerView.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
void setProfilePhotoView(User user) {
    final String url = UserUtils.getProfileImageUrlHttps(user,
            UserUtils.AvatarSize.REASONABLY_SMALL);
    if (imageLoader != null) {
        // Passing null url will not trigger any request, but will set the placeholder bg
        imageLoader.load(url).placeholder(mediaBg).into(avatarView);
    }
}
 
Example #14
Source File: TwitterAuthClientTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
private void setupMockAccountService(Call<User> call) {
    final AccountService mockAccountService = mock(AccountService.class);
    when(mockAccountService.verifyCredentials(anyBoolean(), anyBoolean(), eq(true)))
            .thenReturn(call);
    final TwitterApiClient mockApiClient = mock(TwitterApiClient.class);
    when(mockApiClient.getAccountService()).thenReturn(mockAccountService);
    when(mockTwitterCore.getApiClient(any(TwitterSession.class))).thenReturn(mockApiClient);
}
 
Example #15
Source File: TestFixtures.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
public static Tweet createTweetWithVineCard(long id, User user, String text, Card card) {
    return new TweetBuilder()
            .setId(id)
            .setCard(card)
            .setText(text)
            .setUser(user)
            .build();
}
 
Example #16
Source File: TestFixtures.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
static Tweet createRetweet(long id, User retweeter, Tweet retweetedStatus) {
    return new TweetBuilder()
            .setId(id)
            .setUser(retweeter)
            .setRetweetedStatus(retweetedStatus)
            .build();
}
 
Example #17
Source File: TestFixtures.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
static Tweet createTweet(long id, User user, String text, String timestamp,
        boolean isFavorited) {
    return new TweetBuilder()
            .setId(id)
            .setUser(user)
            .setText(text)
            .setCreatedAt(timestamp)
            .setFavorited(isFavorited)
            .setEntities(new TweetEntities(null, null, null, null, null))
            .build();
}
 
Example #18
Source File: TwitterLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void fetchUserInfo(final BaseToken token) {
    mSubscribe = Flowable.create(new FlowableOnSubscribe<TwitterUser>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<TwitterUser> userEmitter) {

            TwitterApiClient apiClient = TwitterCore.getInstance().getApiClient();
            Call<User> userCall = apiClient.getAccountService().verifyCredentials(true, false, false);

            try {
                Response<User> execute = userCall.execute();
                userEmitter.onNext(new TwitterUser(execute.body()));
                userEmitter.onComplete();
            } catch (Exception e) {
                ShareLogger.e(ShareLogger.INFO.FETCH_USER_INOF_ERROR);
                userEmitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<TwitterUser>() {
                @Override
                public void accept(@NonNull TwitterUser user) {
                    mLoginListener.loginSuccess(new LoginResultData(LoginPlatform.TWITTER, token, user));
                    LoginUtil.recycle();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) {
                    mLoginListener.loginFailure(new Exception(throwable), ShareLogger.INFO.ERR_FETCH_CODE);
                    LoginUtil.recycle();
                }
            });
}
 
Example #19
Source File: TwitterUser.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
public TwitterUser(User user) {
    if (user == null) {
        return;
    }

    setHeadImageUrl(user.profileImageUrlHttps);
    setHeadImageUrlLarge(user.profileBackgroundImageUrlHttps);
    setNickname(user.name);
    setOpenId(user.idStr);
}
 
Example #20
Source File: UserService.java    From twittererer with Apache License 2.0 4 votes vote down vote up
@GET("/1.1/users/show.json")
Call<User> show(@Query("user_id") long id);
 
Example #21
Source File: TimelineConverterTest.java    From twittererer with Apache License 2.0 4 votes vote down vote up
private Tweet createTweet(String createdAt, String text, String name, String screenName, String profileImageUrl) {
    User user = new User(false, null, false, false, null, null, null, 0, false, 0, 0, false, 0, null, false, null, 0, null, name, null, null, null, false, null, profileImageUrl, null, null, null, null, null, false, false, screenName, false, null, 0, null, null, 0, false, null, null);
    return new Tweet(null, createdAt, null, null, null, 0, false, null, 0, null, null, 0, null, 0, null, null, null, false, null, 0, null, null, 0, false, null, null, text, null, false, user, false, null, null, null);
}
 
Example #22
Source File: FabricTwitterKitModule.java    From react-native-fabric-twitterkit with MIT License 4 votes vote down vote up
@GET("/1.1/users/show.json")
Call<User> show(@Query("user_id") Long id);
 
Example #23
Source File: AccountService.java    From twitter-kit-android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an HTTP 200 OK response code and a representation of the requesting user if
 * authentication was successful; returns a 401 status code and an error message if not. Use
 * this method to test if supplied user credentials are valid.
 *
 * @param includeEntities (optional) The entities node will not be included when set to false.
 * @param skipStatus (optional) When set to either true statuses will not be included in
 *                   the returned user objects.
 * @param includeEmail (optional) When set to true email will be returned in the user object as
 *                     a string. If the user does not have an email address on their account, or
 *                     if the email address is not verified, null will be returned.
 */
@GET("/1.1/account/verify_credentials.json")
Call<User> verifyCredentials(@Query("include_entities") Boolean includeEntities,
                             @Query("skip_status") Boolean skipStatus,
                             @Query("include_email") Boolean includeEmail);