我想从 Facebook 用户那里获取 id,但到目前为止我尝试过的方法不起作用......
public class fbLogin extends Activity {
public static final int LOGIN = Menu.FIRST;
public static final int GET_EVENTS = Menu.FIRST + 1;
public static final int GET_ID = Menu.FIRST + 2;
public static final String APP_ID = "361579407254212";
public static final String TAG = "FACEBOOK CONNECT";
private Facebook mFacebook;
private AsyncFacebookRunner mAsyncRunner;
private Handler mHandler = new Handler();
private static final String[] PERMS = new String[] { "user_events","email" };
private TextView mText;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
// setup the content view
initLayout();
// setup the facebook session
mFacebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
if (mFacebook.isSessionValid()) {
AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(mFacebook);
asyncRunner.logout(this, new LogoutRequestListener());
} else {
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
mAsyncRunner.request("me", new IDRequestListener());
}
protected void initLayout() {
LinearLayout rootView = new LinearLayout(this.getApplicationContext());
rootView.setOrientation(LinearLayout.VERTICAL);
this.mText = new TextView(this.getApplicationContext());
this.mText.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
rootView.addView(this.mText);
this.setContentView(rootView);
}
private class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {}
public void onFacebookError(FacebookError e) {}
public void onError(DialogError e) {}
public void onCancel() {}
}
private class LogoutRequestListener implements RequestListener {
public void onComplete(String response, Object state) {
// Dispatch on its own thread
mHandler.post(new Runnable() {
public void run() {
mText.setText("Logged out");
}
});
}
public void onIOException(IOException e, Object state) {}
public void onFileNotFoundException(FileNotFoundException e, Object state) {}
public void onMalformedURLException(MalformedURLException e, Object state) {}
public void onFacebookError(FacebookError e, Object state) {}
}
private class IDRequestListener implements RequestListener {
public void onComplete(String response, Object state) {
try {
// process the response here: executed in background thread
Log.d(TAG, "Response: " + response.toString());
JSONObject json = Util.parseJson(response);
final String id = json.getString("id");
fbLogin.this.runOnUiThread(new Runnable() {
public void run() {
mText.setText("Hello there, " + id + "!");
}
});
} catch (JSONException e) {
Log.w(TAG, "JSON Error in response");
mText.setText("catch1...");
} catch (FacebookError e) {
mText.setText("catch2");
}
}
public void onIOException(IOException e, Object state) {mText.setText("Logging out...1");}
public void onFileNotFoundException(FileNotFoundException e, Object state) {mText.setText("Logging out...2");}
public void onMalformedURLException(MalformedURLException e,Object state) {mText.setText("Logging out...3");}
public void onFacebookError(FacebookError e, Object state) {mText.setText("Logging out...4");}
}
}
当我从课堂上转到该OnComplete
方法时,它给出了一个 Facebook 错误......IDRequestListener
我该如何解决?任何人都可以帮助我吗?