【问题标题】:Can I share images on Twitter without Twitter app我可以在没有 Twitter 应用程序的情况下在 Twitter 上分享图像吗
【发布时间】:2017-04-14 11:37:28
【问题描述】:

我正在尝试通过我的应用在 Twitter 上分享图片。我在我的代码中使用TweetComposer 在 Twitter 上共享图像,但它只共享文本而不共享图像。即使它没有给出任何错误或异常。所以,我想确认是否可以在没有应用程序的情况下在 Twitter 上分享图像?

【问题讨论】:

标签: android twitter feed


【解决方案1】:

是的,您可以在没有应用程序的情况下在 Twitter 上共享图像或链接 使用此代码。首先在库中添加 socialauth 4.4.jar 文件,然后

 private SocialAuthAdapter socialAuthAdapter;
 if (Utils.isOnline(activity)) {
                    // Initialize the socialAuthAdapter with ResponseListener
                    pd = ProgressDialog.show(activity, null, null);
                    socialAuthAdapter = new SocialAuthAdapter(new ResponseListener(
                            share));
                    // Add Twitter to set as provider to post on twitter
                    socialAuthAdapter.addProvider(SocialAuthAdapter.Provider.TWITTER, R.drawable.twitter);
                    // this line is for Authorize start
                    socialAuthAdapter.authorize(activity, SocialAuthAdapter.Provider.TWITTER);
                } else {
                    // showing message when internet connection is not available
                    Toast.makeText(activity,
                            "Check your internet connection..", Toast.LENGTH_LONG)
                            .show();
                }

并实现一个响应监听器

   private class ResponseListener  implements DialogListener {
        String message;

        public ResponseListener(String message) {

            this.message = message;
        }



        @Override
        public void onComplete(final Bundle values) {
            // this method is call when successfull authorization is done
            try {
                socialAuthAdapter.updateStatus(message, new UploadImageListener(),true);
                new SHARE_POST().execute();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(SocialAuthError error) {
            // this method is call when error is occured in authorization
            if (pd != null && pd.isShowing())
                pd.dismiss();
            Log.d("ShareTwitter", "Authentication Error: " + error.getMessage());
        }

        @Override
        public void onCancel() {
            // this method is call when user cancel Authentication
            if (pd != null && pd.isShowing())
                pd.dismiss();
            Log.d("ShareTwitter", "Authentication Cancelled");
        }

        @Override
        public void onBack() {
            // this method is call when user backpressed from dialog
            if (pd != null && pd.isShowing())
                pd.dismiss();
            Log.d("ShareTwitter", "Dialog Closed by pressing Back Key");
        }
    }

    private final class UploadImageListener implements
            SocialAuthListener<Integer> {

        @Override
        public void onError(SocialAuthError e) {
        }

        @Override
        public void onExecute(String arg0, Integer arg1) {
            Integer status = arg1;
            try {
                if (status.intValue() == 200 || status.intValue() == 201
                        || status.intValue() == 204) {
                    if (pd != null && pd.isShowing())
                        pd.dismiss();
                    Toast.makeText(activity, "Image Uploaded",
                            Toast.LENGTH_SHORT).show();
                } else {
                    if (pd != null && pd.isShowing())
                        pd.dismiss();
                    Toast.makeText(activity, "Image not Uploaded",
                            Toast.LENGTH_SHORT).show();
                }

            } catch (NullPointerException e) {
                if (pd != null && pd.isShowing())
                    pd.dismiss();
                Toast.makeText(activity, "Image not Uploaded",
                        Toast.LENGTH_SHORT).show();
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-14
    • 2013-05-15
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    相关资源
    最近更新 更多