0
我完全按照在Facebook上的開發人員頁面告知在Facebook上登錄的人。我的代碼運行良好。 但是,當用戶註銷並嘗試再次通過Facebook登錄時,它會給出無效的密鑰哈希錯誤。我不知道我的代碼有什麼問題。Android的Facebook 4.0.1無效的密鑰哈希錯誤
的Manifest.xml
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:theme="@android:style/Theme.NoTitleBar" >
<activity
android:name="com.example.helltop.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".GameActivity"
android:screenOrientation="portrait"></activity>
<activity
android:name=".HelpActivity"
android:screenOrientation="portrait"></activity>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<meta-data
android:name="com.facebook.sdk.ApplicationName"
android:value="@string/facebook_app_name" />
<provider android:authorities="com.facebook.app.FacebookContentProvider137..."
android:name="com.facebook.FacebookContentProvider"
android:exported="true"/>
</application>
登錄活動
CallbackManager callbackManager;
LoginButton btnFbLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.loginactivity);
btnFbLogin = (LoginButton) findViewById(R.id.btn_fblogin); btnFbLogin.setOnClickListener(this);btnFbLogin.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
fbLoginGetUserData(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Toast.makeText(LoginActivity.this, "Facebook Login Canceled!" , Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException error) {
Toast.makeText(LoginActivity.this, "ERROR : " + error.getMessage() , Toast.LENGTH_SHORT).show();
}
});
btnFbLogin.setReadPermissions(Arrays.asList("public_profile", "email", "user_birthday"));
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
}
};
}
private void fbLoginGetUserData(AccessToken accessToken) {
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if(response.getError() != null){
showAlert(response.getError().getErrorCode() + " : " + response.getError().getErrorMessage(), "Facebook Error!");
} else {
// Get the data here
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,first_name,last_name,link,birthday,email,gender,middle_name");
request.setParameters(parameters);
request.executeAsync();
}
在這裏,我如何創建我的版本的密鑰庫和我的應用程序對於Facebook的哈希鍵。
keytool -genkey -alias myreleasekey-keyalg RSA -keystore %USERPROFILE%\.android\myapprelease.keystore -keysize 2048 -validity 10000
keytool -exportcert -alias myreleasekey -keystore ~/myapprelease.keystore | "C:\OpenSSL\bin\openssl" sha1 -binary | "C:\OpenSSL\bin\openssl" base64
我應該運行在releasekeystore文件籤我的應用程序的第一個活動代碼?對?因爲我記得我也是這樣做的。 – eskimoo
在您的基本應用程序類中運行此代碼,並從日誌貓複製散列密鑰並將其用於設置部分。 – user2273146
,但在發佈模式下處於調試模式。例如,每當我從eclipse運行我的應用程序時,它都是通過調試keysore來構建的。沒有關於這個的規範? – eskimoo