Make sure your Twitter app is registered on Android

My application that I am developing launches the official mail screen of the official Twitter application so that the user can post a tweet with additional text added in the intent. This works fine for me, but it gets a little confusing if the user is not logged in with the Twitter app. The application starts, but the user must log in, as soon as they have done this, a normal twitter screen will appear, if they use the "Back" button to return to my application, a new message screen will appear on the screen after it appears again on the screen Twitter channel.

Is there a way to verify that the user is actually subscribed to the Twitter app before trying to launch the intent?

+7
source share
4 answers

I think this is an internal issue with the Twitter app and you cannot check it.

On the other hand, you can provide Dialog with a warning to the user on this issue with the "Do not show this dialog box anymore" checkbox, so he receives recommendations and can permanently deprive Dialog. You can even provide authentication instructions to close the Twitter application in this dialog.

+3
source

I am using twitter4j lib. Here I check the username. If the username is null, then the user is not registered, otherwise I get the username. This username is available in the access token, which I save in general preferences.

username = mySession.getUsername ();

username = (username.equals ("))?" Not authorized ": username;

code for mySession: -

public class MySession { private SharedPreferences sharedPref; private Editor editor; private static final String TWEET_AUTH_KEY = "auth_key"; private static final String TWEET_AUTH_SECRET_KEY = "auth_secret_key"; private static final String TWEET_USER_NAME = "user_name"; private static final String SHARED = "Twitter_Preferences"; public TwitterSession(Context context) { sharedPref = context.getSharedPreferences(SHARED, Context.MODE_PRIVATE); editor = sharedPref.edit(); } public void storeAccessToken(AccessToken accessToken, String username) { editor.putString(TWEET_AUTH_KEY, accessToken.getToken()); editor.putString(TWEET_AUTH_SECRET_KEY, accessToken.getTokenSecret()); editor.putString(TWEET_USER_NAME, username); editor.commit(); } public void resetAccessToken() { editor.putString(TWEET_AUTH_KEY, null); editor.putString(TWEET_AUTH_SECRET_KEY, null); editor.putString(TWEET_USER_NAME, null); editor.commit(); } public String getUsername() { return sharedPref.getString(TWEET_USER_NAME, ""); } public AccessToken getAccessToken() { String token = sharedPref.getString(TWEET_AUTH_KEY, null); String tokenSecret = sharedPref.getString(TWEET_AUTH_SECRET_KEY, null); if (token != null && tokenSecret != null) return new AccessToken(token, tokenSecret); else return null; } } 

Hope this helps you.

+3
source

Try this function, which in turn will return you the value true or false.

True : Logged False : not logged in

twitter.getAuthorization() function will give you an error message if it does not log in, after processing this, you can find out if the user has been previously registered or not.

 public static boolean isAuthenticated(SharedPreferences prefs) { String token = prefs.getString(OAuth.OAUTH_TOKEN, ""); String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, ""); AccessToken a = new AccessToken(token,secret); Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET); try { twitter.getAuthorization(); return true; } catch (Exception e) { return false; } } 
0
source

just add these lines in oncreate () in ur activity

 final Session activeSession = Twitter.getInstance().core.getSessionManager().getActiveSession(); if (activeSession != null){ //do someting } 
0
source

All Articles