[英]facebook android call function does not work after facebook login
I am trying to make a simple app in which when the user logins the facebook, the user's name is displayed in the textview. 我正在尝试制作一个简单的应用程序,当用户登录Facebook时,用户的名字会显示在textview中。 The problem is that textview does not change. 问题是textview不会改变。 I think there is some problem with the call back function. 我认为回调函数存在一些问题。 This is the code for the MainActivity. 这是MainActivity的代码。 Regards 问候
package com.example.firstfacebook;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// TextView welcome = (TextView) findViewById(R.id.welcome);
//welcome.setText("Hello!");
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
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() + "!");
}
}
});
}
}
});
}
/*public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
}
}
I am using android simple Facebook library
project for login and posting.You don't have to call any callback method externally. 我正在使用android simple Facebook library
项目进行登录和发布。您不必在外部调用任何回调方法。 This library take care of all callbacks. 该库负责所有回调。 You might be interested in this sample project made using this library. 您可能对使用此库创建的此示例项目感兴趣。 Just have a look at it. 看看吧。
I hope this will use full to you. 我希望这对你充分利用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.