0

我在许多教程中都遇到了一个错误,现在我正在尝试这个教程,问题是当资源管理器打开时,我登录到 Twitter,当 twitter 要求授权时,我点击了登录按钮,但没有任何反应,比如我说,我在很多教程中都有这个问题,不只是这个,我做错了什么?

顺便说一句,我添加了这个类来修复 NetworkOnUI 错误:

private class Logintw extends AsyncTask<Void, Void, Uri> {

    @Override
    protected Uri doInBackground(Void... params) {
        try {
            requestToken = twitter
                    .getOAuthRequestToken(TWITTER_CALLBACK_URL);
        } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return Uri.parse(requestToken.getAuthenticationURL());
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
     */
    @Override
    protected void onPostExecute(Uri result) {
        Intent in = new Intent(Intent.ACTION_VIEW, result);
        in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getApplicationContext().startActivity(in
                );
        super.onPostExecute(result);
    }

}
4

2 回答 2

0
protected void onNewIntent(Intent intent) {
    Uri uri = intent.getData();
        if (uri != null && uri.toString().startsWith(TWITTER_CALLBACK_URL)) {
            String verifier = uri
                .getQueryParameter(URL_TWITTER_OAUTH_VERIFIER);
            try {
                // Get the access token
                AccessToken accessToken = twitter.getOAuthAccessToken(TrequestToken, verifier);
                // Shared Preferences
                mPrefs=getPreferences(MODE_PRIVATE);
                Editor e = mPrefs.edit();
                // After getting access token, access token secret store them in application preferences
                e.putString(PREF_KEY_OAUTH_TOKEN, accessToken.getToken());
                e.putString(PREF_KEY_OAUTH_SECRET,accessToken.getTokenSecret());
                // Store login status - true
                e.putBoolean(PREF_KEY_TWITTER_LOGIN, true);
                e.commit(); // save changes
                long userID = accessToken.getUserId();
                User user = twitter.showUser(userID);
                String username = user.getName();
                TwitterLogin=true;
                checkloginstatus();
                new updateTwitterStatus().execute(username+ " is using http://AllPagesManager.com , Try it Now!!!");
                } catch (Exception e) {
                    // Check log for login errors
                    Log.e("Twitter Login Error", "> " + e.getMessage());
                    }
于 2013-04-03T06:18:01.270 回答
0
private void loginToTwitter() {
    // Check if already logged in
    if (!isTwitterLoggedInAlready()) {
        try {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
        builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
        Configuration configuration = builder.build();
        TwitterFactory factory = new TwitterFactory(configuration);
        twitter = factory.getInstance();
            TrequestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
            this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(TrequestToken.getAuthenticationURL())));
        } catch (TwitterException e) {
            e.printStackTrace();
        }
    } else {
        Toast.makeText(getApplicationContext(),"Already Login to twitter!-----", Toast.LENGTH_SHORT).show();
        TwitterLogin=true;
        checkloginstatus();

    }
}
于 2013-04-03T06:09:46.793 回答