I am developing an Android application and want to integrate Twitter.
I understand that if the official Android application for Android is installed on the user device, we can authenticate using the account manager as sketched here .. and if it is not installed, then show the Twitter login web page.
Do I understand correctly?
Authentication using the twitter login web page now works fine. But how do I log in with my account manager?
Using AccountsType as "com.twitter.android.auth.login" I have a token and token using the account manager β’ com.twitter.android.oauth.token β’ com.twitter.android.oauth.token.secret
I use Twitter4J and authenticate with CONSUMER_KEY and CONSUMER_SECRET along with recvd. tokens. but authentication always fails.
CONSUMER_KEY and CONSUMER_SECRET are the keys that I received when I registered the application on twitter ... but I do not understand how I can use these keys with official Android authentication of Twitter?
Pls. let me know thanks
Here is my code
public class TwitterAuthentication { private static final String TAG = "TwitterAuthentication"; private static final int MSG_GOT_AUTH_TOKEN = 100; private static final int MSG_GOT_AUTH_SECRET = 101; private static final int MSG_NO_AUT_TOKEN_RECVD = 102; public static Twitter mTwitter = null; private Activity mActivity = null; private SharedPreferences prefs; private MessageHandler handler = new MessageHandler(); public static boolean bAuthenticationDone = false; public TwitterAuthentication(Activity activity){ mActivity = activity; prefs = PreferenceManager.getDefaultSharedPreferences(mActivity); if (null == mTwitter){ mTwitter = new TwitterFactory().getInstance();; mTwitter.setOAuthConsumer(Constant.CONSUMER_KEY, Constant.CONSUMER_SECRET); bAuthenticationDone = false; } } public void LoginTwitter(){ if (Constants.DEBUG)Log.d(TAG,"LoginTwitter"); if (bAuthenticationDone){ TwitterSessionEvents.onLoginSuccess(); } else if (!isSessionValid()){ AuthTwitter(); } else{ bAuthenticationDone = true; TwitterSessionEvents.onLoginSuccess(); } } public boolean isSessionValid(){ boolean ret = false; if (null != prefs && null != mTwitter){ String token = prefs.getString(Constant.OAUTH_TOKEN, ""); String secret = prefs.getString(Constant.OAUTH_TOKEN_SECRET, ""); if (null != token && null != secret && token.length()>0 && secret.length()>0){ AccessToken a = new AccessToken(token,secret); mTwitter.setOAuthAccessToken(a); try { mTwitter.getAccountSettings(); keys.User_Id = mTwitter.getScreenName(); ret = true; } catch (TwitterException e) { ret = false; } } } return ret; } public void AuthTwitter(){
Naveen
source share