我在我的应用程序中使用 Twitter API 发布状态并检索它,我尝试了太多迄今为止最好的代码,没有错误。我从发布状态开始,但我没有收到错误,但没有发布状态
我的代码:
public class Asy extends AsyncTask<String, Void,MainActivity> {
private Exception exception;
public static String consumerKey = "**************";
public static String consumerSecret = "************";
public final static String accesstoken= " *************";
public final static String accesstokensecret="*******";
private final String CALLBACKURL = "T4J_OAuth://callback_main";
Twitter twitter ;
protected MainActivity doInBackground(String... urls) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(consumerKey);
builder.setOAuthConsumerSecret(consumerSecret);
Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance();
try {
AccessToken a = new AccessToken(acc,accsec);
twitter.setOAuthAccessToken(a);
twitter.updateStatus("First trial on twitter");
} catch (TwitterException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return null;
}
protected void onPostExecute(MainActivity feed) {
// TODO: check this.exception
// TODO: do something with the feed
}
}
我使用了异步任务,并在我的主要活动中通过以下方式调用它:
Asy task= new Asy ();
task.execute();