如何发布从一个Android应用程序鸣叫一个特定的帐户? [英] How to post a tweet from an Android app to one specific account?

查看:116
本文介绍了如何发布从一个Android应用程序鸣叫一个特定的帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选项添加到我的游戏发布高分到Twitter。我们的想法是,应用程序有它自己的Twitter帐户,用户可以上传分数这个特定的帐户上的按钮或菜单项的点击(还没有决定用户界面的长相还)。

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).

我发现有很多的教程是这样的:  <一href="http://blog.doityourselfandroid.com/2011/02/13/guide-to-integrating-twitter-android-application/" rel="nofollow">http://blog.doityourselfandroid.com/2011/02/13/guide-to-integrating-twitter-android-application/ ,这显示了如何张贴到Twitter的应用程序,但在所有这些解决方案,用户需要登录与他/她自己的帐户。

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. 首先,你需要在Twitter上创建帐户您的应用程序
  2. 转到此页面,并与创建的帐户登录
  3. 将鼠标移到您的帐户名,在右上角 点击我的应用
  4. 单击创建一个新的应用程序右侧
  5. 填写表格,创建应用程序
  6. 进入设置,并在设置访问类型应用程序类型 读与写,并保存设置
  7. 返回到详细信息页面,向下滚动至底部,并点击 创建访问令牌按钮
  8. 使用这些生成的令牌和其他的人(消费者键和 消费者的秘密),这是上面显示pviously产生这些$ P $ 在同一页面上标记发布的鸣叫从你的应用程序
  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

这里的code我用我的应用程序:

Here's the code I used in my app:

您需要包括在 twitter4j-核心的Andr​​oid-2.2.5.jar 包这一点。你可以从这里下载:<一href="http://twitter4j.org/archive/twitter4j-android-2.2.5.zip">http://twitter4j.org/archive/twitter4j-android-2.2.5.zip

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();
            }

        }
    });

这篇关于如何发布从一个Android应用程序鸣叫一个特定的帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆