简单JTwitter为Android例如简单、JTwitter、Android

2023-09-05 04:57:01 作者:8.Gentle(温柔)

我已经尝试了许多不同的方式,并搜索所有在互联网上找到了一个教程,使用JTwitter使用OAuth。以下是接下来的步骤我已经完成

I have tried many different way and search all over the internet to find a tutorial to use JTwitter with OAuth. Here are the following step I have accomplish

下载两个Jtwitter和路标 添加它们作为罐在Java生成器

Download both Jtwitter and Signpost Add them as Jars in the Java Builder

创建了一个简单的按钮运行

Created a simple button that run

public class ShareGenerator extends Activity {

    private static final String JTWITTER_OAUTH_KEY = "this_is_populated";
    private static final String JTWITTER_OAUTH_SECRET = "this_is_populated";

    Button menupopButton;

     @Override
        public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  setContentView(R.layout.share);
  this.setContentView(R.layout.share);
  this.txShare = (TextView)this.findViewById(R.id.lblshare);
  this.menupopButton = (Button)this.findViewById(R.id.menupop);


  menupopButton.setOnClickListener(new View.OnClickListener()
  { 
      public void onClick(View v) 

      {
          TwitterSend();

      } 
 }); 

     }

和我有我的课

public void TwitterSend () {

                 OAuthSignpostClient client = new OAuthSignpostClient(JTWITTER_OAUTH_KEY, JTWITTER_OAUTH_SECRET, "oob");
                    Twitter jtwit = new Twitter("bob", client);
                    // open the authorisation page in the user's browser
                    client.authorizeDesktop();
                    // get the pin
                    String v = client.askUser("Please enter the verification PIN from Twitter");
                    client.setAuthorizationCode(v);
                    // Optional: store the authorisation token details
                    Object accessToken = client.getAccessToken();
                    // use the API!
                    jtwit.setStatus("Messing about in Java");

             }

不过,我甚至不能OAuth的屏幕上弹出。它崩溃,当它到达那里。谁能帮我至少看到OAuth的屏幕?我有进口设置是否正确。

However I can't even get the OAuth screen to pop up. It crashes when it get there. Can anyone help me at least see the OAuth screen? I do have the import set correctly.

推荐答案

现在的问题是在这条线,它使用的java.awt.Desktop:

The problem is in this line, which uses java.awt.Desktop:

// open the authorisation page in the user's browser
client.authorizeDesktop();

这将工作在台式机上,而不是在Android上。

That will work on a desktop PC, but not on Android.

相反,采取从的URL client.authorizeUrl(); 并发送用户那里。例如。像这样的东西:

Instead, take the url from client.authorizeUrl(); and send the user there. E.g. with something like this:

URI url = client.authorizeUrl();
Intent myIntent = new Intent(Intent.VIEW_ACTION);
myIntent.setData(url);
startActivity(myIntent);

但我不是一个Android codeR!你几乎可以肯定做用回调,而不是 OOB 的更好。希望别人能提供code为...

But I'm not an Android coder! You can almost certainly do better by using a callback instead of oob. Hopefully someone else can supply the code for that...