我使用以下代码登录Facebook。此登录过程在调试时有效,但不适用于已签名的应用程序。我在Facebook应用程序设置中添加了debug Hash密钥和Release Hash密钥,但没有任何成功。知道是什么导致了这个吗?
package com.priyank.safeboard;
import java.util.Arrays;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.actionbarsherlock.app.SherlockFragment;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.widget.LoginButton;
public class MainFragment extends SherlockFragment {
private static final String TAG = "MainFragment";
private UiLifecycleHelper uiHelper;
Button b;
LoginButton authButton;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.safeboardlogin, container, false);
authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
/*b=(Button) view.findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateDetail();
}
});*/
authButton.setReadPermissions(Arrays.asList("user_location", "user_birthday","user_likes", "user_status"));
return view;
}
protected void updateDetail() {
Intent intent = new Intent();
intent.setClass(getActivity(), MainActivity.class);
startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null &&
session.isOpened() || session.isClosed() ) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
updateDetail();
authButton.setVisibility(View.INVISIBLE);
//b.setVisibility(View.VISIBLE);
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
}
在使用log cat调试应用程序时,我使用以下代码获取应用程序的Key哈希值但是如何获取已签名应用程序的“密钥哈希”?
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("Your Tag", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
答案 0 :(得分:1)
你唯一要改变的是iz应用程序签名,所以很明显有一些哈希值。 Facebook为其页面上的哈希计算提供了错误的方法。今天我也遇到了这个问题 - 这个解决方案:Generating hash key for app using facebook sdk对我来说没问题。