I'm attempting to request certain permissions when I log in to Facebook using the Android SDK. Using the following code, the login is successful, but the permissions I wanted are neither granted nor declined. It appears they were not even requested. What's wrong?
login_button.setReadPermissions(Arrays.asList("user_photos"));
login_button.setFragment(this);
LoginManager.getInstance().registerCallback(PicTag.callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.v(PicTag.TAG, "Facebook login success: " + loginResult.toString());
Log.v(PicTag.TAG, AccessToken.getCurrentAccessToken().getPermissions().toString());
Log.v(PicTag.TAG, loginResult.getRecentlyGrantedPermissions().toString());
if (shareFrag!=null){
shareFrag.shareContent();
activity.getSupportFragmentManager().popBackStackImmediate();
}
}
#Override
public void onCancel() {
// App code
Log.v(PicTag.TAG, "Facebook login canceled");
}
#Override
public void onError(FacebookException exception) {
// App code
Log.v(PicTag.TAG, "Facebook login error: " + exception.toString());
if (shareFrag!=null){
activity.getSupportFragmentManager().popBackStackImmediate();
}
}
});
}
According to "user_photos" Permissions documentation:
If your app requests this permission Facebook will have to review how your app uses it.
This is a new Facebook policy and you will most likely need to sumbit you application for Login Review.
Related
I am getting an exception when I click on the facebook button displayed in the image. The steps I am doing are listed below.
1) I am login in from my application when facebook is already installed on my mobile.
2) After that I uninstall the facebook application from my phone.
3) Now I start my application again and try to share the image but that shows the following error in toast.
Here is my code
mBinding.fragSocailmediaShareFb.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
CM.setSp(getActivity(), CV.SOCIALMEDIA_FB_ID, loginResult.getAccessToken().getUserId());
ShareOnFB();
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
if (CM.getSp(getActivity(), CV.SOCIALMEDIA_FB_ID, "").toString().length() > 0) {
ShareOnFB();
} else {
mBinding.fragSocailmediaShareFb.performClick();
}
Thank you in advance.
so im really confused on how the facebook login works with aws cognito in android. I was able to hook aws cognito up and the facebook log in just fine. The aws cognito guide gives me these lines of code:
Map<String, String> logins = new HashMap<String, String>();
logins.put("graph.facebook.com", AccessToken.getCurrentAccessToken().getToken());
credentialsProvider.setLogins(logins);
couple questions:
1.Where do i put these lines of code?
2.How do i set up cognito user equal to the login facebook user?
3.And basically, whats a working example of this?
Hope you guys can help!
This is the following code where I have used the facebook login with federated identities from the congnito. first you need to set up the CognitoSyncManagerFile with the appropriate login credentials with the pool details . And then the following code as follows .
//initialize the facebook SDK
FacebookSdk.sdkInitialize(getApplicationContext());
//If access token is already here, set fb session
final AccessToken fbAccessToken = AccessToken.getCurrentAccessToken();
if (fbAccessToken != null) {
setFacebookSession(fbAccessToken);
// btnLoginFacebook.setVisibility(View.GONE);
}
btnLoginFacebook = (Button) findViewById(R.id.btnLoginFacebook);
btnLoginFacebook.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// start Facebook Login
LoginManager.getInstance().logInWithReadPermissions(MainActivity.this, Arrays.asList("public_profile"));
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
btnLoginFacebook.setVisibility(View.GONE);
new GetFbName(loginResult).execute();
setFacebookSession(loginResult.getAccessToken());
}
#Override
public void onCancel() {
Toast.makeText(MainActivity.this, "Facebook login cancelled",
Toast.LENGTH_LONG).show();
}
#Override
public void onError(FacebookException error) {
Toast.makeText(MainActivity.this, "Error in Facebook login " +
error.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
//Set the session with the following method
private void setFacebookSession(AccessToken accessToken) {
Log.i(TAG, "facebook token: " + accessToken.getToken());
CognitoSyncClientManager.addLogins("graph.facebook.com",
accessToken.getToken());
}
For more information follow the below url
https://github.com/awslabs/aws-sdk-android-samples/tree/master/CognitoSyncDemo
Put this in a spot where your credentials provider has already been initialized, where you have just logged in to Facebook for the user in question.
Once you have included this in the logins map, call credentialsProvider.refresh(). This will link the login to the user's identity.
The official AWS samples repo has an android sample that does all this.
I am using facebook sdk 4.9.0 for facebook login. Facebook login is working correctly but what I want is every time user tries to do login with facebook he should be shown facebook login screen.
Currently, if user is already logged in to the facebook app, facebook login screen is not shown but I get success for login request.
Here is code that I am using
public void goToFacebookLogin() {
LoginManager.getInstance().logOut();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Timber.i("FB login success:" + loginResult.getAccessToken().getToken());
}
#Override
public void onCancel() {
Timber.e("FB login cancel");
showErrorMessage(getString(R.string.string_error_facebook_login_cancelled));
}
#Override
public void onError(FacebookException error) {
Timber.e("FB login error:" + Log.getStackTraceString(error));
showErrorMessage(getString(R.string.string_error_facebook_login));
}
});
if (fbPermissions.isEmpty()) {
fbPermissions.addAll(Arrays.asList(getResources().getStringArray(R.array.string_array_fb_permissions)));
}
if (Utils.isNetworkAvailable(this)) {
showProgressBar();
LoginManager.getInstance().logInWithReadPermissions(this, fbPermissions);
} else {
showErrorMessage(getString(R.string.string_error_no_network));
}
}
you have to initialise the FacebookSDK.
use FacebookSDK.SDKInitialize().
Thanks to #kishansolanki124 for mentioning this. This method is deprecated. The work around is mentioned here.
GraphRequest(AccessToken.getCurrentAccessToken(),
"/me/permissions/", null, HttpMethod.DELETE,
GraphRequest.Callback {
AccessToken.setCurrentAccessToken(null)
LoginManager.getInstance().logOut()
}).executeAsync()
I am trying to get the publish_actions permission from the user for my app. The user has already logged in through facebook and in that instance I asked for some read permissions that the app needs. Getting the read permissions worked fine but there seems to be some problem with publish_actions. My code is:
private void asktopublish() {
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
CallbackManager callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Toast.makeText(getApplicationContext(), "Done", Toast.LENGTH_LONG);
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
}
When the user clicks the button on my to grant the permission, the Facebook activity opens but closes almost instantly and seems to be empty as well.
I've tried looking for other solutions online but they all use the older fb sdk.
As #MBat suggested, I added the user as a tester and it works
I had source code:
List<String> listPermission = Arrays.asList("email", "public_profile", "user_friends", "read_page_mailboxes", "read_insights");
List<String> listPermissionPublish = Arrays.asList("manage_pages", "publish_actions");
loginButton.setReadPermissions(listPermission);
loginButton.setPublishPermissions(listPermissionPublish);
loginButton.registerCallback(((HomeActivity) getActivity()).getCallbackManager(), new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
I using Facebook SDK 4.0 for Android.
But i had a problem getReadPermission and getPublishPermission on one request.
I see in: Get Read and Publish Permissions in one request
However in Facebook SDK 4.x is Session Removed.
Thanks for watching.
You can not ask for both permissions simultaneously. First get read permission and then ask for publish permission. I am calling this method from a button listener.
void requestPublishPermissions() {
// Requesting publish permissions
LoginManager.getInstance().logInWithReadPermissions(
this,
Arrays.asList("user_managed_groups", "user_groups"));
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
}