0
代碼:Facebook的方法isSessionValid()總是在Android中返回false
public void onClick(View v) {
if(fb.isSessionValid())
{
Log.i("Checking isSessionValid()","Inside isSessionValid()");
try {
fb.logout(getApplicationContext());
updatebuttonimage();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
Log.i("","Jumped isSessionValid");
fb.authorize(MainActivity.this,new String[]{"email"},new DialogListener() {
public void onFacebookError(FacebookError e) {
Toast.makeText(MainActivity.this,"FacebookError",Toast.LENGTH_SHORT).show();
}
.....
當我試圖檢查isSessionValid(),它始終返回false,並沒有進入method.I有也嘗試添加在的onCreate()下面的代碼,但它打印相同KeyHash在我的logcat所以沒有用:
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.example.facebook_integration",
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) {
} catch (NoSuchAlgorithmException e) {
}
幫助將非常感激你們。提前致謝。