I have written a code to login using facebook button sdk 4.0. I am able to login/logout. There is an activity for user from where user can share their locally saved picture to facebook. Sharing is possible if native facebook app is installed. But not in case facebook is not installed. So I tried to use ShareApi for sharing pictures via web view. But it requires publish actions permission. So I just written following code to get permission. It opens a window where it ask for per ok and cancel with my app name. After pressing ok button it always falls in onCancel case automatically.
I have read somewhere that you need to submit your app for review to facebook team in order to take publish actions permission. Is this only reason i am not getting success after trying almost 18 hours.?? Please help me friends.
List<String> permissionNeeds = Arrays.asList("publish_actions");
LoginManager loginManager = LoginManager.getInstance();
loginManager.logInWithPublishPermissions(activity,permissionNeeds);
loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
System.out.println("onSuccess" + loginResult);
sharePhotoToFacebook();
}
#Override
public void onCancel() {
System.out.println("onCancel");
}
#Override
public void onError(FacebookException error) {
System.out.println("onError"+error);
}
});
Related
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.
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
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 want to get the profile details from Facebook. I am using the latest Facebook SDK. I want to use custom login button to login and get profile details of user.
In onSuccess method i am getting LoginSuccess object . Now i am stuck how i got user profile data . And this code is on facebookButton not on custom button. Please give me some ideas to integrate the SDK via custom button. I go through the facebook documentation but do not got anything useful.
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
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
}
}
);
You can get simple user info (like name and id) by using in onSuccess() loginManager method Profile class:
Profile.getCurrentProfile() //get current instance of logged profile
Profile.getCurrentProfile().getId() //get current id
Profile.getCurrentProfile().getName() //get current user name
If you want to fetch more information about user, like email or date of birth, you should to use GraphAPI request. You can read about it in related question answer.
It doesn't matter, if you are using Custom Login button or not. In both situations SDK is using loginManager.
I have seen numerous stackoverflow posts but none of them seem to be helping me in this problem.
When I try to login using facebook, the facebook app opens, asks for permissions and then when I click OK, everything goes into background. There is nothing in the logs.
Things that I have already tried:
I have created app on Facebook developer console
Added Android as platform on Settings page, added package name, class name and generated key hash. Then i also added the key hash from the logcat error with = at the end.
I have added my email address in contact, and made my app go live in Status & Review.
I have installed and logged in to Facebook app on my android device.
I have tried deleting my debug.keystore, and generating new hash
I have tried deleting Facebook developer app and creating it from scratch
I am using LoginManager to sign-in to facebook from my android app.
Here is my code for login:
private void loginWithFacebook() {
final LoginManager loginManager = LoginManager.getInstance();
CallbackManager callbackManager = CallbackManager.Factory.create();
loginManager.registerCallback(
callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(final LoginResult loginResult) {
Log.e("WelcomeScreen", "onSuccess");
}
#Override
public void onCancel() {
Log.e("WelcomeScreen", "onCancel");
}
#Override
public void onError(FacebookException e) {
Log.e("WelcomeScreen", "onError");
}
}
);
loginManager.logInWithReadPermissions(this, Arrays.asList("public_profile"));
}
I have already done this in onCreate:
FacebookSdk.sdkInitialize(getApplicationContext());
I figured out the problem. In my manifest, I had specified noHistory to true for the activity where I was expecting the activity result back from Facebook activity, but since the activity is destroyed once it launches another activity, the app was shutting down. Removing the hoHistory resolved the issue.