Facebook SDK 4.x, setReadPermissions and setPublishPermissions - android

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"));
}

Related

Facebook login on Android TV

I'm trying to implement the Facebook login on my Android TV app.
I've been following this little guide: https://developers.facebook.com/docs/android/devices
But I can't make it work.
Here is a sample of my code:
mCallbackManager = CallbackManager.Factory.create();
DeviceLoginManager loginManager = new DeviceLoginManager();
loginManager.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
connectWithFacebook(loginResult.getAccessToken().getToken());
}
#Override
public void onCancel() {
loginFailed();
}
#Override
public void onError(FacebookException e) {
loginFailed();
}
});
List<String> permissions = new ArrayList<>();
permissions.add("email");
loginManager.logInWithReadPermissions(activity, permissions);
I'm getting the webview popup with the email and password fields (like on mobile) instead of getting this one:
facebook login
Thanks a lot for the help!
It's a bug in DeviceLoginManager that I spent a lot of time to find out.
You must to set the LoginBehavior as DEVICE_AUTH before the call of logInWithReadPermissions.
loginManager.setLoginBehavior(LoginBehavior.DEVICE_AUTH);
loginManager.logInWithReadPermissions(activity, permissions);
And, also, add this metaData in your Manifest:
<meta-data
android:name="com.facebook.sdk.ClientToken"
android:value="#string/client_token" />
Probably they'll fix that sometime in the future, since they already did with the DeviceLoginButton

facebook image sharing using facebook api not working with other account in android

In my current project I've on task that is image sharing from our app to facebook. I've created project in my developer's account also.
In my app image sharing working with developers account. And I've made my developers account as public. Login is working but sharing is not working.
For every time it's going oncancel method in registerCallback.
callbackManager = CallbackManager.Factory.create();
List<String> permissionNeeds = Arrays.asList("publish_actions");
//this loginManager helps you eliminate adding a LoginButton to your UI
manager = LoginManager.getInstance();
manager.setLoginBehavior(LoginBehavior.WEB_ONLY);
manager.logInWithPublishPermissions(this, permissionNeeds);
manager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
sharePhotoToFacebook();
}
#Override
public void onCancel() {
System.out.println("onCancel");
}
#Override
public void onError(FacebookException exception) {
System.out.println("onError");
}
});
In case of sharing anything to facebook you need to submit your app to facebook for review.
check this for more.
Here is the whole guideline for app review process.

How to make a post or share button on Facebook in android

Facebook just driving me crazy! I have no idea, what they are trying to get from me. The thing is that I want to is to make SHARE button inside my Android app. What code I should write in order to get similar window?
This is the pic what I wanna do:
http://s29.postimg.org/pvgbhv1dz/151020_0002.png
This is the code how I do it now:
case FB_ID:
FacebookSdk.sdkInitialize(getApplicationContext());
fbCallbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
LoginManager.getInstance().registerCallback(fbCallbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "FB");
openFragment(MakeWallPostFragment.newInstance(social_id,null), false);
// App code
}
#Override
public void onCancel() {
// App code
finish();
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
break;
This code give me this kind of error:
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions")); //this is the culprit string gives me:
The publish_actions permissions are missing,
the share will fail unless this app was authorized to publish in another installation. this error
What should I use to make it happen?
Btw, this is the video with explanation, but I think all this stuff is deprecated now:http://www.youtube.com/watch?v=iBBVkwBeaY4

Unable to get Facebook Publish Permission - Android

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

Can't request permissions from Android Facebook SDK

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.

Categories

Resources