Issue with Android Facebook SDK - android

in my activity I use the following code to get Facebook authorization. facebook.authorize is called but it does not enter in one of the listener event (onComplete, onFacebookError...). Anybody could help?
Facebook facebook = new Facebook(FACEBOOK_APPID);
facebook.authorize(ItemDetail.this, new String[] {"publish_stream"},
new DialogListener() {
#Override
public void onComplete(Bundle values) {
Log.i("ItemDetail", "Facebook onComplete");
}
#Override
public void onFacebookError(FacebookError error) {
Log.i("ItemDetail", "Facebook onFacebookError");
}
#Override
public void onError(DialogError e) {
Log.i("ItemDetail", "Facebook onError");
}
#Override
public void onCancel() {
Log.i("ItemDetail", "Facebook onCancel");
}
}
);

You need to put this in your class:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
facebook.authorizeCallback(requestCode, resultCode, data);
}

Related

Facebook sdk ShareDialog registerCallback methods not working - Facebook Android SDK

The registerCallback method of ShareDialog is not working. Toast is not being displayed for any of the registerCallback methods. Only the share dialog shows.
Requirement - I want to know if the user has successfully shared the post or discarded it.
private void shareRateButtonClickListeners() {
flFbShare.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("http://androidlift.info"))
.build();
shareDialog.show(getActivity(), linkContent);
}
});
callbackManager = CallbackManager.Factory.create();
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Toast.makeText(getActivity().getApplicationContext(), "Share success!", Toast.LENGTH_SHORT).show();
Log.e(TAG,"Fb onSuccess");
}
#Override
public void onCancel() {
Toast.makeText(getActivity().getApplicationContext(), "Did not share", Toast.LENGTH_SHORT).show();
Log.e(TAG,"Fb onCancel");
}
#Override
public void onError(FacebookException error) {
Toast.makeText(getActivity().getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
Log.e(TAG,"Fb onError");
}
}, 90);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
Please make sure your activity has implement this function
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
Document: https://developers.facebook.com/docs/sharing/android/

Login doesn't work using LoginManager

The facebook login is showing, I logged into facebook, confirmed the information, but when I go back to my app the AccessToken did not work. When I tested:
FacebookSdk.sdkInitialize(getApplicationContext(), new FacebookSdk.InitializeCallback() {
#Override
public void onInitialized() {
if(AccessToken.getCurrentAccessToken() == null){
System.out.println("not logged in yet");
} else {
System.out.println("Logged in");
}
}
});
the result is not logged in yet
This is the code login:
public void loginFacebook(View v){
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Toast.makeText(UserPerfilActivity.this, "VocĂȘ Clicou em: ", Toast.LENGTH_LONG).show();
System.out.println("publish");
// sharePhotoToFacebook();
}
#Override
public void onCancel() {
System.out.println("onCancel");
}
#Override
public void onError(FacebookException exception) {
System.out.println("onError");
}
});
}
But the callbackManager doesn't work, I don't have publish or cancel or error println.
Fix the problem, I added this code:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode,
resultCode, data);
}
this is the post:
post stackoverflow link

Android facebook Status on sharing complete or not

I am using latest Facebook SDK for sharing link. I am using standard code that is given in the tutorial. But so far I am unable to know the status of post.
i.e. whether user posts through Facebook dialog or cancelled it I always receive null/same values.
As it is important part of my application logic. I want to know whether user really posted or not.
Code I am using in activity result:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("hariss",resultCode+"");
uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
#Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
Log.e("Activity", String.format("Error: %s", error.toString()));
}
#Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i("Activity", "Success!");
//tried various things here to know weather user posted or not, but failed
}
});
}
Use the below method for posting and you can do the later task in onComplete method.
public void postToWall() {
// post on user's wall.
facebook.dialog(this, "feed", new DialogListener() {
#Override
public void onFacebookError(FacebookError e) {
}
#Override
public void onError(DialogError e) {
}
#Override //enter code here
public void onComplete(Bundle values) {
}
#Override
public void onCancel() {
}
});
}

Facebook Integration with Android App Error

I am trying to integrate Facebook ** into my android app. I want to implement **like and share ** facility on **facebook. But i am getting error.
please help me to solve this.
Also I want to know the process of creating New App on Facebook.
I am using code from GitHub. My code is -
public class MyGreatActivity extends Activity {
Facebook facebook = new Facebook("333778590046892");
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
facebook.authorize(this, new String[] { "offline_access", "publish_stream", "raj21kadam#gmail.com" },
new DialogListener() {
#Override
public void onComplete(Bundle values) {
String token=facebook.getAccessToken(); //get access token
// Toast.makeText(this, "token", Toast.LENGTH_LONG).
save(token);
}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
private void save(String token){
Toast.makeText(this, "token"+token, Toast.LENGTH_LONG).show();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putString("Token", token).commit();
}
}
I am getting the following error while running the above code -
Dialog Errorcom.facebook.android.DialogError: The connection to the server was unsuccessful.
try this Single Sign On (SSO) Using Android Native Client For Facebook .
paste this
facebook.authorize(this, new DialogListener() {
#Override
public void onComplete(Bundle values) {
String token=facebook.getAccessToken(); //get access token
// Toast.makeText(this, "token", Toast.LENGTH_LONG).
save(token);
}
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
}
instead of this
facebook.authorize(this, new String[] { "offline_access", "publish_stream", "raj21kadam#gmail.com" },
new DialogListener() {
#Override
public void onComplete(Bundle values) {
String token=facebook.getAccessToken(); //get access token
}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
}

Android FB Connect

I am trying to integrate the official FB SDK for android.
below is the basic code
public class FbTestActivity extends Activity {
Facebook facebook = new Facebook("112374492201730");
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
facebook.authorize(this, new String[] { "email", "read_stream" },
new DialogListener() {
public void onComplete(Bundle values) {
}
public void onFacebookError(FacebookError error) {
}
public void onError(DialogError e) {
}
public void onCancel() {
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
}
When i open the app the Login or (if looged in) Permission dialog never shows up. Some dialog opens for a few mili secs and closes down.
The problem is the SSO (Single Sign On) feature of the login.
Following link will help you.
facebook login dialog disappears soon after loading
http://ukgupta.blogspot.com/2011/07/facebook-implementation-into-android.html

Categories

Resources