I want to make a program about Twitter on Android.
The code is like this:
public class ShareGenerator extends Activity {
priv开发者_开发百科ate final static String JTWITTER_OAUTH_KEY = "********";
private final static String JTWITTER_OAUTH_SECRET ="***********"
Button menupopButton;
TextView txShare;
@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.setText("login");
menupopButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
OAuthSignpostClient client = new OAuthSignpostClient(JTWITTER_OAUTH_KEY, JTWITTER_OAUTH_SECRET, "oob");
URI url = client.authorizeUrl();
client.setAuthorizationCode("pin");
String[] accessToken = client.getAccessToken();
Twitter jtwit = new Twitter("cnitwoker", client);
jtwit.setStatus("Messing about in Java");
}
});
}
The code is taken from an example, but there may be something wrong. What is "oob"? How can I get the pin?
I am getting the following error:
:03-22 17:24:21.087: ERROR/AndroidRuntime(30260): winterwell.jtwitter.TwitterException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: The operation timed out.....
From the docs, http://www.winterwell.com/software/jtwitter/javadoc/winterwell/jtwitter/OAuthSignpostClient.html, out-of-bounds, desktop based, that won't work in your android app.
I think you should be using xAuth, see this for and example: Android Twitter xAuth example using twitter4j
精彩评论