我用這簡單的代碼:安卓:Facebook的登錄不從這裏工作
段要求:
https://developers.facebook.com/docs/mobile/android/build/#sig
public class MainActivity extends Activity {
Facebook facebook = new Facebook("xxxxxxxxxxxxxx");
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
private SharedPreferences mPrefs;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this, new String[] {}, new DialogListener() {
@Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
}
@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);
try {
JSONObject json = Util.parseJson(facebook.request("me"));
String facebookID = json.getString("id");
String firstName = json.getString("first_name");
String lastName = json.getString("last_name");
String email = json.getString("email");
String gender = json.getString("gender");
} catch (Exception e) {
//If i click Okay i get Exception saying You need an Active access token to get the current user details
}
}
}
使用這讓哈希鍵一個密碼(「android」)
並給我像這樣的代碼:
xLYMxxxxxx/0enePexxf4DORUfR8 =
,並在Facebook應用我的配置是:
但我得到這個錯誤:
如果我按好吧,我得到th e異常說明您需要一個活動訪問令牌來獲取當前用戶詳細信息。
我嘗試了在SOF上給出的所有可能的解決方案。但沒用。請幫忙
謝謝你
看看com.facebook.android.Utils類的代碼。 set private static boolean ENABLE_LOG = true;當您嘗試登錄時觀察LogCat輸出。 – Agata
Yeah.it總是如此,從未在logcat中向我展示過任何東西。 :( –
我也是「配置錯誤登錄」的錯誤,過了一段時間後,原來Facebook想要不同的keyhash,然後我有,出於某種原因 – Agata