我在这里使用这个简单的代码:
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 应用程序中,我的配置是:
但我得到这个错误:
如果我按下 Okay,我会得到一个异常,说你需要一个 Active 访问令牌来获取当前用户详细信息。
我尝试了 SOF 上给出的所有可能的解决方案。但是没有用。请帮忙
谢谢你