您好我是Android开发的新手,我看了这个教程Facebook auth for Android
并在我的 FacebookActivity.java
中这是我的代码:
package net.proudcloud.guestlistph;
import android.app.Activity;
import android.os.Bundle;
import com.facebook.model.*;
import com.facebook.*;
import android.content.Intent;
import android.widget.TextView;
public class FacebookActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook);
//start facebook login
Session.openActiveSession(this, true, new Session.StatusCallback() {
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
TextView welcome = (TextView) findViewById(R.id.welcome);
welcome.setText("Hello " + user.getName() + "!");
}
}
}).executeAsync();
}
}
@Override
public void call(Session session, SessionState state,
Exception exception) {
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}