Android FacebookSDK's AppInviteDialog.canShow() returns false - android

I'm having problems with the AppInviteDialog provided by Facebook.
I'm using the following code snippet to show the dialog
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(appLinkUrl)
.setPreviewImageUrl(previewImageUrl)
.build();
AppInviteDialog.show(activity, content);
}
The problem is the sentence AppInviteDialog.canShow() is returning false.
In the Facebook Developers page, they say no login is required to invite people
App Invites does not require Facebook Login.
But I noticed the AppInviteDialog.canShow() only returns true when I make login in my app. But if I close it an open again the dialog can not show.
Have any ideas what's going on?

Please see this answer. canShow() returns false typically when the content you're trying to share is not supported by the web version.

Related

Share to FB messages from android code with button and image from URL

I would like to update the Facebook SDK version in my app to the latest and am trying to replicate the messenger sharing functionality that I had before.
With Facebook SDK 12.3.0 the following code leads to a post like the one in below image.
val button = ShareMessengerURLActionButton.Builder()
.setTitle("This is the button title")
.setUrl(Uri.parse("https://google.com"))
.build()
val builderElement = ShareMessengerGenericTemplateElement.Builder()
.setTitle("This is the message title")
.setButton(button)
.setImageUrl(Uri.parse("https://w7.pngwing.com/pngs/243/287/png-transparent-homer-simpson-bart-simpson-lisa-simpson-the-simpsons-tapped-out-maggie-simpson-bart-simpson-homer-simpson-bart-simpson-lisa-simpson.png"))
.build()
val content = ShareMessengerGenericTemplateContent.Builder()
.setPageId(SocialConstants.FACEBOOK_PAGE_ID)
.setGenericTemplateElement(builderElement)
.build()
if (MessageDialog.canShow(ShareMessengerGenericTemplateContent::class.java)) {
MessageDialog.show(activity, content)
}
With the latest SDK version 15.1.0, the classes ShareMessengerGenericTemplateElement and ShareMessengerGenericTemplateContent are gone, but ShareMessengerURLActionButton is still there and not even deprecated anymore like before. But how can I use the action button now? Is there a way to achieve a similar message as before?
FYI: Cross post from the facebook community forum to reach a wider audience.

Spotify Authentication auth_service_unavailable

I am trying to login to spotify.
Although when the app is installed it always throws an AUTHENTICATION_SERVICE_UNAVAILABLE error. If the app is uninstalled the default Webview opens where the login works fine. Wished behaviour is, that the app opens and the user can login from there.
public void doSpotifyLogin(boolean trySpotifyAgain) {
this.trySpotifyAgain = trySpotifyAgain;
AuthorizationRequest.Builder builder =
new AuthorizationRequest.Builder(CLIENT_ID, AuthorizationResponse.Type.TOKEN, REDIRECT_URI);
builder.setScopes(new String[]{"user-read-private", "streaming", "playlist-read-private", "user-library-read"});
AuthorizationRequest request = builder.build();
AuthorizationClient.openLoginActivity(this, SPOTIFY_LOGIN_REQUEST_CODE, request);
}
This is the response I am getting from the API:
2021-12-22 11:36:29.802 5069-5069/? I/com.spotify.sdk.android.auth.LoginActivity: Spotify auth completing. The response is in EXTRA with key 'response'
2021-12-22 11:36:29.822 5069-5069/? D/StartActivity: Spotify error: AUTHENTICATION_SERVICE_UNAVAILABLE
If you need any further information, please let me know! Thanks in advance
Ronze's comment worked for me. I needed to update my app's package name on developer.spotify.com.
For me, the issue got resolved after I added the SHA1 key generated on a new mac to the Spotify app dashboard

Deleting a user from Azure Active Directory B2C Android/Java

I have an Android application in which I'm using Azure AD B2C to authenticate users. Users login and logout of the application as needed. I would like to give the user the option to delete their own account.
I understand that I need to use the Azure AD Graph API to delete the user. This is what I have so far:
According to this link, it looks like deleting a user from a personal account (which is what the B2C users are using) is not possible. Is that correct?
Here's my code snippet for the Graph API call. Feel free to ignore it if I'm off track and there is a better way to solve this.
I believe I need a separate access token than what my app currently has (as the graph API requires other API consent). So, I'm getting the access token as follows:
AcquireTokenParameters parameters = new AcquireTokenParameters.Builder()
.startAuthorizationFromActivity(getActivity())
.fromAuthority(B2CConfiguration.getAuthorityFromPolicyName(B2CConfiguration.Policies.get("SignUpSignIn")))
.withScopes(B2CConfiguration.getGraphAPIScopes())
.withPrompt(Prompt.CONSENT)
.withCallback(getGraphAPIAuthCallback())
.build();
taxApp.acquireToken(parameters);
In the getGraphAPIAuthCallback() method, I'm calling the Graph API using a separate thread (in the background):
boolean resp = new DeleteUser().execute(authenticationResult.getAccessToken()).get();
Finally, in my DeleterUser() AsyncTask, I'm doing the following:
#Override
protected Boolean doInBackground(String... aToken) {
final String asToken = aToken[0];
//this method will be running on background thread so don't update UI from here
//do your long running http tasks here,you dont want to pass argument and u can access the parent class' variable url over here
IAuthenticationProvider mAuthenticationProvider = new IAuthenticationProvider() {
#Override
public void authenticateRequest(final IHttpRequest request) {
request.addHeader("Authorization",
"Bearer " + asToken);
}
};
final IClientConfig mClientConfig = DefaultClientConfig
.createWithAuthenticationProvider(mAuthenticationProvider);
final IGraphServiceClient graphClient = new GraphServiceClient.Builder()
.fromConfig(mClientConfig)
.buildClient();
try {
graphClient.getMe().buildRequest().delete();
} catch (Exception e) {
Log.d(AccountSettingFragment.class.toString(), "Error deleting user. Error Details: " + e.getStackTrace());
}
return true;
}
Currently, my app fails when trying to get an access token with a null pointer exception:
com.microsoft.identity.client.exception.MsalClientException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
Any idea what I need to do to provide the user the option to users to delete their own account? Thank you!
Thanks for the help, #allen-wu. Due to his help, this azure feedback request and this azure doc, I was able to figure out how to get and delete users silently (without needing intervention).
As #allen-wu stated, you cannot have a user delete itself. So, I decided to have the mobile app call my server-side NodeJS API when the user clicks the 'Delete Account' button (as I do not want to store the client secret in the android app) and have the NodeJS API call the Azure AD endpoint to delete the user silently. The one caveat is that admin consent is needed the first time you try to auth. Also, I have only tested this for Graph API. I'm not a 100% sure if it works for other APIs as well.
Here are the steps:
Create your application in your AAD B2C tenant. Create a client secret and give it the following API permissions: Directory.ReadWrite.All ;
AuditLog.Read.All (I'm not a 100% sure if we need the AuditLog permission. I haven't tested without it yet).
In a browser, paste the following link:
GET https://login.microsoftonline.com/{tenant}/adminconsent?
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
&state=12345
&redirect_uri=http://localhost/myapp/permissions
Login using an existing admin account and provide the consent to the app.
Once you've given admin consent, you do not have to repeat steps 1-3 again. Next, make the following call to get an access token:
POST https://login.microsoftonline.com/{B2c_tenant_name}.onmicrosoft.com/oauth2/v2.0/token
In the body, include your client_id, client_secret, grant_type (the value for which should be client_credentials) and scope (value should be 'https://graph.microsoft.com/.default')
Finally, you can call the Graph API to manage your users, including deleting them:
DELETE https://graph.microsoft.com/v1.0/users/{upn}
Don't forget to include the access token in the header. I noticed that in Postman, the graph api had a bug and returned an error if I include the word 'Bearer' at the start of the Authorization header. Try without it and it works. I haven't tried it in my NodeJS API yet, so, can't comment on it so far.
#allen-wu also suggested using the ROPC flow, which I have not tried yet, so, cannot compare the two approaches.
I hope this helps!
There is a line of code: graphClient.getUsers("").buildRequest().delete();
It seems that you didn't put the user object id in it.
However, we can ignore this problem because Microsoft Graph doesn't allow a user to delete itself.
Here is the error when I try to do it.
{
"error": {
"code": "Request_BadRequest",
"message": "The principal performing this request cannot delete itself.",
"innerError": {
"request-id": "8f44118f-0e49-431f-a0a0-80bdd954a7f0",
"date": "2020-06-04T06:41:14"
}
}
}

Twitter Kit Android - TwitterApiClient retweet does not work

In my app so far, I am displaying a tweet (my own for now) using the Twitter Kit for Android and have a Retweet button with which I am attempting to (go figure) retweet using the Twitter API Client.
Here are the links I referred to before this:
1) Twitter REST APIs from Android
2) Twitter Community Discussion on Retweeting using the TwitterApiClient
This is the code I'm using:
val twApiClient: TwitterApiClient = TwitterCore.getInstance().apiClient
tbTweet.setOnMenuItemClickListener {
when (it.itemId) {
R.id.item_retweet -> {
val call: Call<Tweet> = twApiClient.statusesService.retweet(tweetID, true)
Log.i("Retweet", if (call.isExecuted) "Successful" else "Failed")
}
}
true
}
I'm not getting any errors but when I go to my Profile Page on twitter, the retweet doesn't show up. The same problem has been stated in the 2nd link I provided, but no solution was given.
I also Log out the Execution Status. It comes as "Failed", so I know that the call retweet() isn't even executing. But why?
What is the problem and how do I fix it?
So, apparently the code above is incomplete. You have to call execute() on the call object that is returned from the retweet(tweetId, true) method. And then, you can call an onCompleteListener to see if your retweet was successful or not.

Facebook SDK : invalide scope : basic info use public_profile, user friends instead

I'm using facebook sdk 3.15 to set a facebook login button on my project.
keep in mind that I'm working with parse.com
I used the code provided by parse.com support, available here but I keep getting this error after I click on the login button :
invalide scope : basic info use public_profile, user friends instead
I googled the error and found nothing...
Thanks for your help :)
You're using Graph API v2.0, hence the permission basic_info is no longer available.
See https://developers.facebook.com/docs/apps/changelog#v2_0_permissions
basic_info is no longer available.
Check what you set as scope parameter in the Login URL.
I have the same problem,like the below image:
Then I change my code from: self.loginView.readPermissions = #[#"basic_info"]; to self.loginView.readPermissions = #[#"public_profile", #"user_friends"]; to solved the problem. With the loginView is declaration into the header file:#property (weak, nonatomic) IBOutlet FBLoginView *loginView;

Categories

Resources