0
當我嘗試從請求中捕獲訪問令牌時,應用程序崩潰。現在我一直有這個麻煩。我可以讓web意圖啓動,然後在確認後回調到應用程序,但是我不確定如何正確獲取返回的令牌。我如何獲得有人驗證後的訪問令牌twitter4j從webintent獲取Oauth
12-03 05:19:17.923: E/AndroidRuntime(3494): FATAL EXCEPTION: main
12-03 05:19:17.923: E/AndroidRuntime(3494): java.lang.RuntimeException: Unable to resume activity {com.example.twwetking/com.example.twwetking.Tweetr}: java.lang.IllegalStateException: Authentication credentials are missing. See http://twitter4j.org/configuration.html for the detail.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tweetr);
//create a new twitter configuration using user details
Configuration twitConf = new ConfigurationBuilder()
.setOAuthConsumerKey(TWIT_KEY)
.setOAuthConsumerSecret(TWIT_SECRET)
.build();
//create a twitter instance
tweetTwitter = new TwitterFactory(twitConf).getInstance();
Button tweetr = (Button)findViewById(R.id.tweetr);
tweetr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dt.execute(points);
}
});
}
public class TweetTask extends AsyncTask<Object, Void, String> {
@Override
protected String doInBackground(Object... values) {
try {
requestToken = tweetTwitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
}
}
@Override
protected void onResume() {
super.onResume();
if (this.getIntent()!=null && this.getIntent().getData()!=null) {
Log.d("KEY", requestToken.getToken().toString()+" SECRET "+requestToken.getTokenSecret().toString());
ACCESS_TOKEN = requestToken.getToken().toString();
ACCESS_TOKEN_SECRET = requestToken.getTokenSecret().toString();
try {
tweetTwitter.updateStatus("I just made a new Top Score On JamTrivia "+points+"points!!!");
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
會考慮它的感謝,:) – kabuto178
導入該項目後得到了一些錯誤,在項目引進一些錯誤 – kabuto178
什麼is..please張貼在這裏.. –