如何使用Fabric从twitter发送电子邮件

时间:2016-12-03 09:57:36

标签: android twitter twitter-fabric

我试图通过面料从Twitter获取电子邮件,任何人都可以帮助我如何获得它。我也试过没有面料,但它没有用。

我的代码如下所示。

    twitterLoginButton.setCallback(new Callback<TwitterSession>() {
                @Override
                public void success(Result<TwitterSession> result) {

                    session = result.data;

                    String username = session.getUserName();
                    Long userid = session.getUserId();

                    Log.d(":: Name ::", session.getUserName());

                    getUserData();
                }

                @Override
                public void failure(TwitterException exception) {

                }
            });
        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            twitterLoginButton.onActivityResult(requestCode, resultCode, data);
        }

        void getUserData() {
        Call<User> call = Twitter.getApiClient(session).getAccountService()
                .verifyCredentials(true, false);
        call.enqueue(new Callback<User>() {
            @Override
            public void success(Result<User> result) {
                User user = result.data;
                String twitterImage = user.profileImageUrl;

                try {
                    Log.d("imageurl", user.profileImageUrl);
                    Log.d("name", user.name);
//                    Log.d("email", user.email);
                    Log.d("des", user.description);
                    Log.d("followers ", String.valueOf(user.followersCount));
                    Log.d("createdAt", user.createdAt);

                    Log.d("::Name ::", user.name);


                    session = Twitter.getSessionManager().getActiveSession();
                    TwitterAuthToken authToken = session.getAuthToken();
                    String token = authToken.token;
                    String secret = authToken.secret;
                    authClient = new TwitterAuthClient();
                    authClient.requestEmail(session, new Callback<String>() {
                        @Override
                        public void success(Result<String> result) {
                            // Do something with the result, which provides the email address
                            Log.d("::::result:::::", result.response + "");
                        }

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


                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void failure(TwitterException exception) {

            }
        });
    }

1 个答案:

答案 0 :(得分:2)

试试这个。

twitauthobj.requestEmail(twitsessionobj,new Callback<String>() {
                        @Override
                        public void success(Result<String> stringResult) {
                            'You code here'

                        }

                        @Override
                        public void failure(TwitterException e) {

                        }
                    });

here is image

您必须检查此添加权限。你检查一下吗?