【问题标题】:how to use twitter api in android application for send tweet only如何在 android 应用程序中使用 twitter api 仅发送推文
【发布时间】:2011-02-21 04:49:58
【问题描述】:

我想了解 twitter api for android 应用程序...... 请向我发送 twitter api 的链接或来源,该 api 仅用于发送推文....

【问题讨论】:

    标签: android


    【解决方案1】:
    String tweetUrl = "https://twitter.com/intent/tweet?text=PUT TEXT HERE &url="
                        + "https://www.google.com";
    Uri uri = Uri.parse(tweetUrl);
    startActivity(new Intent(Intent.ACTION_VIEW, uri));
    

    欲了解更多信息,请查看我在其他帖子中的回答

    How to tweet from Android app?

    【讨论】:

    • @giancarlo 工作正常。但是在 Twitter 上发布后,我怎样才能回到相同的活动?
    • 简单实用。简单的推文不需要 twitter4j。​​
    • @gian1200 你能分享我需要发送的额外意图吗.. 我正在传递 intent.putExtra("text", ArticleListAdapter.shareContent); intent.putExtra("url", ArticleListAdapter.link);这些值,但页面不显示此消息??????
    • 你不需要额外的东西。只是一个带参数的长网址
    【解决方案2】:

    要使用标准的 android Intent 共享一些文本,只需要三行代码。系统将提示用户选择一种方法(然后他们可以选择 Twitter。)

        Intent share = new Intent(Intent.ACTION_SEND);
        share.putExtra(Intent.EXTRA_TEXT, "Here's some text for Twitter.");
        startActivity(Intent.createChooser(share, "Share this via"));
    

    如果你想用 Twitter 做更高级的事情:

    我发现互联网上发布的许多解决方案都是不必要的复杂。对我来说,除了 Twitter4J 告诉你的操作之外,只需要添加几行代码。

    对于我来说,Stephan's answer here 是最好的。

    我在 github 上有一些使用他的技术的示例代码,here

    【讨论】:

      【解决方案3】:

      代码:

      protected String doInBackground(String... args) {
      
                ConfigurationBuilder builder = new ConfigurationBuilder();
                builder.setOAuthConsumerKey(CONSUMER_KEY);
                builder.setOAuthConsumerSecret(CONSUMER_SECRET);
                AccessToken accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
                Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
                try {
            twitter4j.Status response = twitter.updateStatus(tweetText);
            return response.toString();
          } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
             return null;
             }
      

      【讨论】:

        猜你喜欢
        • 2014-09-12
        • 1970-01-01
        • 2017-09-20
        • 2014-02-21
        • 1970-01-01
        • 2013-10-06
        • 2020-07-12
        • 2012-05-20
        相关资源
        最近更新 更多