I know that's a question answered before, but no one seems to work and i spend a week on int.
I tried to get my Key Hash from key tool and put them on Facebook app Key hashes, release and debug. No one worked. "(404) Key hash xxxxxxxxxxxx does not match any storeed key hashes" That's rare, my keys are different.
So i tried:
PackageInfo info = getPackageManager().getPackageInfo(
"com.pakage.example",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String result = Base64.encodeToString(md.digest(), Base64.DEFAULT);
Toast.makeText(MainActivity.this , result + result.toUpperCase(), Toast.LENGTH_LONG).show();
}
That return me the same Key Has request by Facebook (xxxxxxxxxxxx), so i added them to Facebook App, but Facebook return me "(404) Key hash xxxxxxxxxxxx does not match any storeed key hashes".
When i removed Facebook App from my device, i was avaliebe to share status via WebDialog.
My final code seems to:
if (FacebookDialog.canPresentShareDialog(parent, FacebookDialog.ShareDialogFeature.SHARE_DIALOG))
{
publishFacebookDialog(points); //FacebookDialog
}
else
{
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
publishFeedDialog(points); //WebDialog
}
else
{
Intent intent = new Intent(parent, LoginUsingCustomFragmentActivity.class); //From FacebookSDK demo
parent.startActivityForResult(intent, 666);
}
}
PublishFacebookDialog function:
private void publishFacebookDialog(String puntuacion) {
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(parent)
.setLink("bla")
.setCaption("bla")
.setName("bla")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
PublishFeedDialog function:
private void publishFeedDialog(String puntuacion) {
Bundle params = new Bundle();
params.putString("name", "bla");
params.putString("caption", "bla");
params.putString("link", "bla");
WebDialog feedDialog = ( new WebDialog.FeedDialogBuilder(parent,Session.getActiveSession(),params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
final String postId = values.getString("post_id");
if (postId != null) {
} else {
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
} else {
// Generic, ex: network error
}
}
})
.build();
feedDialog.show();
}
The LoginUsingCustomFragmentActivity class is the same that FacebookSDK
Tried:
Any idea?
Lot of thanks.
I was facing the same problem, the hash code that i generated through openssl was wrong i then used this function and it help. Hope it help you all too.
private void printKeyHash() {
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo("YOUR PACKAGE NAME", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
Log.e("KeyHash:", e.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("KeyHash:", e.toString());
}
}
Use the hash code that is printed in logs and enjoy. Happy Coding :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With