如何从安卓应用发布推文到一个特定账户?[英] How to post a tweet from an Android app to one specific account?

本文是小编为大家收集整理的关于如何从安卓应用发布推文到一个特定账户?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我必须为我的游戏添加一个选项,以将高速搜索到Twitter.这个想法是该应用程序拥有自己的Twitter帐户,并且用户可以用点击按钮或菜单项(尚未决定UI如何看起来)将分数上传到此特定账户.

我已经找到了许多这样的教程: http://blog.doityourselfandroid.com/2011/02/13/指南集成 - Twitter-Android应用/ ,其中显示如何从应用程序发布到推特,但在所有这些解决方案中,用户需要与他/她自己的帐户登录.

欢迎任何建议.谢谢.

推荐答案

我已经找到了这个问题的解决方案.以为我在这里分享它,以防有人有同样的问题.

    首先,首先需要在Twitter上为您的应用程序创建帐户
  1. 转到此页并使用创建的帐户登录
  2. 将鼠标移动到右上角的帐户名称上 单击"我的应用程序"
  3. 单击右侧的"创建新应用程序"
  4. 填写表格并创建应用程序
  5. 转到设置,并在应用程序类型设置访问类型 "读写"并保存设置
  6. 返回"详细信息"页面并向下滚动到底部,然后单击 "创建访问令牌"按钮
  7. 使用这些生成的令牌和另一个("消费者键"和 "消费者秘密")如上所述所示 同一页面上的令牌到您的App
  8. 发布推文

这是我的应用程序中使用的代码:

您需要包含 twitter4j-core-android-2.2.5.jar 包.您可以从这里下载它: http://twitter4j.org/archive/twitter4j- Android-2.2.5.zip

    tweet=(Button)findViewById(R.id.tweetbtn);
    message=(EditText)findViewById(R.id.messagetxt);

    tweet.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            String token ="<Your access token>"; 
            String secret = "<Your access token secret>";
            AccessToken a = new AccessToken(token,secret);
            Twitter twitter = new TwitterFactory().getInstance();
            twitter.setOAuthConsumer("<Your consumer key>", "<Your consumer secret>");
            twitter.setOAuthAccessToken(a);
            try {
                twitter.updateStatus(message.getText().toString());
            } catch (TwitterException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

其他推荐答案

下载的新链接

http://twitter4j.org/archive/twitter4j-android-2.2. 5.zip

旧链接不起作用

本文地址:https://www.itbaoku.cn/post/102338.html

问题描述

I have to add an option to my game for posting highscores to twitter. The idea is that the app has it's own twitter account and the user can upload the score to this specific account with a click on a button or a menu item (haven't decided how the UI looks like yet).

I have found many tutorials like this: http://blog.doityourselfandroid.com/2011/02/13/guide-to-integrating-twitter-android-application/ ,which show how to post to twitter from apps but in all of these solutions the user needs to login with his/her own account.

Any suggestions are welcome. Thank you.

推荐答案

I have found a solution for this problem. Thought I share it here in case anyone has the same problem.

  1. First you need to create the account for your app on twitter
  2. Go to this page and log in with the created account
  3. Move your mouse over your account name in the upper right corner and click "My applications"
  4. Click on "Create a new application" on the right
  5. Fill in the form and create the application
  6. Go to Settings and under Application type set the Access type to "Read and Write" and save the settings
  7. Return to the "Details" page and scroll down to the bottom and click the "Create access token" button
  8. Use these generated tokens and the other ones ("Consumer key" and "Consumer secret") which are shown above these previously generated tokens on the same page to post tweets from your app

Here's the code I used in my app:

You need to include the twitter4j-core-android-2.2.5.jar package for this. You can download it from here: http://twitter4j.org/archive/twitter4j-android-2.2.5.zip

    tweet=(Button)findViewById(R.id.tweetbtn);
    message=(EditText)findViewById(R.id.messagetxt);

    tweet.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            String token ="<Your access token>"; 
            String secret = "<Your access token secret>";
            AccessToken a = new AccessToken(token,secret);
            Twitter twitter = new TwitterFactory().getInstance();
            twitter.setOAuthConsumer("<Your consumer key>", "<Your consumer secret>");
            twitter.setOAuthAccessToken(a);
            try {
                twitter.updateStatus(message.getText().toString());
            } catch (TwitterException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

其他推荐答案

the new link for download

http://twitter4j.org/archive/twitter4j-android-2.2.5.zip

old link does not work