public class PrepareRequestTokenActivity extends Activity { public static final String CONSUMER_KEY = "Hr8aDOFeDdY9UbvQB0w2w"; public static final String CONSUMER_SECRET= "wfZOJYkYVEYrmdmltOaKfRdnUfSiUkr2MQdjRUY2xU"; public static final String REQUEST_URL = "http://twitter.com/oauth/request_token"; //"https://API.twitter.com/oauth/request_token" public static final String ACCESS_URL = "http://twitter.com/oauth/authorize"; //"https://API.twitter.com/oauth/authorize" public static final String AUTHORIZE_URL = "http://twitter.com/oauth/access_token"; //"https://API.twitter.com/oauth/access_token" final public static String OAUTH_CALLBACK_SCHEME = "droIDnotify-oauth-twitter"; final public static String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME + "://callback"; private boolean _deBUG = false; private OAuthConsumer _consumer; private OAuthProvIDer _provIDer; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); _deBUG = Log.getDeBUG(); if (_deBUG) Log.v("PrepareRequestTokenActivity.onCreate()"); try { _consumer = new CommonshttpOAuthConsumer(CONSUMER_KEY,CONSUMER_SECRET); //_provIDer = new CommonshttpOAuthProvIDer(REQUEST_URL,ACCESS_URL,AUTHORIZE_URL); _provIDer = new DefaultOAuthProvIDer(REQUEST_URL,AUTHORIZE_URL); } catch (Exception ex) { if (_deBUG) Log.e("PrepareRequestTokenActivity.onCreate() Error creating consumer / provIDer: " + ex.toString()); } if (_deBUG) Log.v("PrepareRequestTokenActivity.onCreate() Starting task to retrIEve request token."); new OAuthRequestTokenTask(this,_consumer,_provIDer).execute(); } @OverrIDe public voID onNewIntent(Intent intent) { super.onNewIntent(intent); if (_deBUG) Log.v("PrepareRequestTokenActivity.onNewIntent()"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final Uri uri = intent.getData(); if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) { if (_deBUG) Log.v("PrepareRequestTokenActivity.onNewIntent() Callback received : " + uri); if (_deBUG) Log.v("PrepareRequestTokenActivity.onNewIntent() RetrIEving Access Token"); new RetrIEveAccesstokenTask(this,_provIDer,prefs).execute(uri); finish(); } } public class RetrIEveAccesstokenTask extends AsyncTask<Uri,VoID,VoID> { private Context _context; private OAuthProvIDer _provIDer; private OAuthConsumer _consumer; private SharedPreferences _prefs; public RetrIEveAccesstokenTask(Context context,OAuthConsumer consumer,OAuthProvIDer provIDer,SharedPreferences prefs) { _context = context; _consumer = consumer; _provIDer = provIDer; _prefs=prefs; } @OverrIDe protected VoID doInBackground(Uri...params) { final Uri uri = params[0]; final String oauth_verifIEr = uri.getqueryParameter(OAuth.OAUTH_VERIFIER); try { _provIDer.retrIEveAccesstoken(_consumer,oauth_verifIEr); final Editor edit = _prefs.edit(); edit.putString(OAuth.OAUTH_TOKEN,_consumer.getToken()); edit.putString(OAuth.OAUTH_TOKEN_SECRET,_consumer.getTokenSecret()); edit.commit(); String token = _prefs.getString(OAuth.OAUTH_TOKEN,""); String secret = _prefs.getString(OAuth.OAUTH_TOKEN_SECRET,""); _consumer.setTokenWithSecret(token,secret); //_context.startActivity(new Intent(_context,AndroIDTwitterSample.class)); //executeAfteraccesstokenRetrIEval(); Toast.makeText(_context,"Twitter Authentication Successfull",Toast.LENGTH_LONG); Toast.makeText(_context,"OAuth.OAUTH_TOKEN KEY: " + OAuth.OAUTH_TOKEN + ",OAuth.OAUTH_TOKEN Value: " + _consumer.getToken(),"OAuth.OAUTH_TOKEN_SECRET KEY: " + OAuth.OAUTH_TOKEN_SECRET + ",OAuth.OAUTH_TOKEN_SECRET Value: " + _consumer.getTokenSecret(),Toast.LENGTH_LONG); if (_deBUG) Log.v("OAuth - Access Token RetrIEved"); } catch (Exception ex) { if (_deBUG) Log.e("OAuth - Access Token RetrIEval Error: " + ex.toString()); } return null; } } }解决方法 只需将一个布尔标志初始化为false,使其在PrepareRequestTokenActivity的onNewIntent()函数中为true,并在onResume函数中添加一个if条件,如果此标志为false则完成活动,如果为true则不执行任何 *** 作,即单击后退按钮时从浏览器它直接转到onResume,此时你的标志将是假的,然后这个活动将完成,当成功或不,谢谢它将首先转到onNewIntent()然后onResume,所以是真的然后活动将不会完成 总结
以上是内存溢出为你收集整理的在android中,Twitter4j API没有重定向到按下按钮的应用程序全部内容,希望文章能够帮你解决在android中,Twitter4j API没有重定向到按下按钮的应用程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)