Display Twitter user profile without logging in? - java

I would like to display a twitter user profile without having the app prompt the phone user for creating an account or login information.
public void openTwitter(View view){
try
{
// Check if the Twitter app is installed on the phone.
getPackageManager().getPackageInfo("com.twitter.android", 0);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.twitter.android", "com.twitter.android.ProfileActivity");
intent.putExtra("user_id", 01234567L);
startActivity(intent);
}
catch (PackageManager.NameNotFoundException e)
{
// If Twitter app is not installed, start browser.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/xxx")));
}
}
The code opens the twitter app and prompts the phone user for account creation before viewing profile xxx. I would like to simply view profile xxx without creating an account or logging in.

Welcome to StackOverflow. Please check out how to ask a good question first. Your question doesn't describe a specific problem and therefore can't be "solved". It also isn't specific enough for anyone to point you in the direction of methods to use to achieve your goal.
That being said, if you just want to display anyone's profile, implement the Twitter API in your app and make the right REST calls and you should get the information you want to display.
If you want the user's profile specifically, there's literally no way around the user logging into their account with the API, unless they previously define their username in your app.
If you just want to display the profile and don't care about designing the information yourself, you could use a WebView to open the link to the profile you want to open, or use UIApplication.shared.open to open a link outside your own app.

Related

MSAL ANDROID : MultiAccountMode issue with Logout

I have an android native application using MSAL library to authenticate. We are facing issues to logout from application after login. While logout, it displays a screen where the already logged in email displays, tapping on that allows the user to login to the application with out a password. The application is configured as MultiAccount mode. Below is the code for logout.
removeAccountButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mMultipleAccountApp == null) {
return;
}
/**
* Removes the selected account and cached tokens from this app (or device, if the device is in shared mode).
*/
mMultipleAccountApp.removeAccount(accountList.get(accountListSpinner.getSelectedItemPosition()),
new IMultipleAccountPublicClientApplication.RemoveAccountCallback() {
#Override
public void onRemoved() {
Toast.makeText(getContext(), "Account removed.", Toast.LENGTH_SHORT)
.show();
/* Reload account asynchronously to get the up-to-date list. */
loadAccounts();
}
#Override
public void onError(#NonNull MsalException exception) {
displayError(exception);
}
});
}
});
It always display the toast "Account removed", but it is actually not. Any help is appreciated!
Edit 1 - 12/12/2022
#Tinjzz This Answer is almost your exact scenario.
Question Description
"accounts are removed successfully, but when signing in again and the microsoft sign in intent is opened, the accounts can just be clicked to sign in without password"
#Rutha answer "This is happening because MSAL automatically refreshes your token after expiration. When user opens your app it checks if that token is already present and valid."
"you need to remove the cache as well to remove the account from the cache, find the account that need to be removed and then call PublicClientApplication.removeAccount()"
In a later answer, #Rutha notes "On Android we basically don't have any control on the cookies" "If you want the user to enter the password again then you should do this: AcquireTokenInteractive(scopes).WithPrompt(Prompt.ForceLogin);
Old Response
From the code posted, it looks like you are using an approach similar to this site with a separate loadAccounts() method. "Step 5.2: Load accounts"
However, in the MS MSAL Single and Multi-Account page, it notes:
"If your app is configured to use a broker, and a broker is installed on the device, the account won't be removed from the broker when you call removeAccount. Only tokens associated with your client are removed."
MS specifically recommends using "Call getAccounts to get a list of accounts currently known to the app."
So, the current setup may be using loadAccounts() per the first link, yet MS actually recommends getAccounts that specifically addresses only the internal MSAL token system.

Spotify logout on android

i have this code to log in to spotify in my app. I using the offical spotify lib.
public void spotifyLoginBtnClicked(View v){
//start the authentication for spotify
AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(clientID, AuthenticationResponse.Type.TOKEN, redirectURI);
builder.setScopes(new String[]{"user-read-private", "streaming"});
AuthenticationRequest request = builder.build();
// open LoginActivity
AuthenticationClient.openLoginActivity(this, activityIdentification, request);
}
Im wondering now how i can create a logout button. Because once logged in, if i press the login button again, it just returns. So i'am unable to change the user. I havent found anything in the java doc.
I just found this document which looks similar to the code you pasted for logging in.
In there it mentions a few methods for logging the user out but I think the main block of code you will need is:
To log out and clear all stored tokens, use the AuthenticationClient#clearCookies method. Both Spotify and Facebook tokens will be removed.
I would go and check that article I linked above as there is edge cases that might be important for your project.
Happy Coding!

Always open android webview Login dialog when user logged out from my app

I've integrated Facebook in my app and the user can login, share and post things. I've implemented a logout also.
Here is my problem: when user wants to log in, the Facebook SDK checks whether the native app is present or not.
If the native Facebook app is not installed in the user's device then it will open a webview dialog like the image below (First image).
If the user has the Facebook app, then my app directly asks him/her for permissions without opening the loginUI (Second Image)
.
I want to show the Facebook loginUI always.
Each time the user wants to login.
Please help me.
Yeah i did it....
if anyone in future face this situation this solution may help them
For opening webdialog during login with facebook
If you are using facebook login button, we need to set the property called as "SessionLoginBehaviour" then write the below code.
loginButton.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
refer this
You can check it if facebook installed using this method :
private boolean isFacebookExist(){
try{
ApplicationInfo info = getPackageManager().
getApplicationInfo("com.facebook.katana", 0 );
return true;
} catch( PackageManager.NameNotFoundException e ){
return false;
}
}

Android: Link to dropbox and Login to account programmatically

I am able to follow these instructions to set up dropbox for an android app. However, I want to able able to log in to the desired account programmatically. The instruction startlink like this to prompt for login.
mAccountManager.startLink((Activity)MyActivity.this, REQUEST_LINK_TO_DBX);
How can I log in programmatically so that the user is not prompted?
You should be doing something like this:
if(mAccountManager.hasLinkedAccount()){
mAccount = mAccountManager.getLinkedAccount();
}
else{
mAccountManager.startLink((Activity) MyActivity.this, prefs.getInt("REQUEST_LINK",0));
}
The drop box api will store the account on the device, the user will have to log in the first time and then the above code will use getLinkedAccount() to automatically login to dropbox.

bringing up different page when logged in

let me start off by saying happy holidays to everyone!
ok i really just need confirmation and correction if needed.
what im trying to do:
Im using google and facebook "Log-in" feature to sign in for my app to retrieve the data needed like name email etc.
where i Need help:
after signing in i want another activity to be the forefront everytime app opens unless the user signs out then of course, it takes them back to the original main page to sign back in.
now im assuming this takes place in maybe the lifecycle right?
somthing like:
#override
OnResume
{
//if user is signed in cast an Intent to automatically go to another activity?
}
am i on the right track on no? thanks in advance guys
I'm not sure off the top of my head how Google and Facebook's login is implemented... do they have a sample project you're using?
And yep, you're on the right track! Generally speaking you should be able to have a "Main" activity (MainActivity for this example) which checks to see if the login was successful, and if so, kicks you to the activity you want (LoggedInActivity).
This would be in the onCreate() or onResume() method of MainActivity.java
onResume() { // onCreate() should work, too.
if (loggedIn) {
startActivity(new Intent(this, LoggedInActivity.class));
} else {
// send them to login
}
}
If there's not a good way to check if they're logged in, you could save a boolean value or api token using SharedPreferences once the login is successful, and check that value (that'd be the value of loggedIn) every time at launch. You'd obviously need to clear that value any time you logged out.

Categories