我用facebook登录按钮创建了一个应用程序。我想要那个,当我成功登录到facebook去另一个意图...我写了一些代码,但我有一些'怪异'的错误(我的意见)
到目前为止,这是我的代码:
public class LogIn extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_log_in);
AppEventsLogger.activateApp(this);
View view = inflater.inflate(R.layout.splash, container, false);
LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions("email");
loginButton.registerCallback(callbackmanager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Intent i = new Intent(this, MainPannel.class);
startActivity(i);
}
public void onCancel() {
}
public void onError(FacebookException exception) {
}
});
}
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("LogIn Page")
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
public void onStart() {
super.onStart();
}
public void onStop() {
super.onStop();
}
}
这些是错误:
Error:(33, 9) error: cannot find symbol variable loginButton
Error:(33, 37) error: cannot find symbol variable view
Error:(37, 38) error: cannot find symbol variable callbackmanager
Error:(41, 28) error: no suitable constructor found for Intent
请帮助:(
答案 0 :(得分:0)
首先用应用程序实现facebook。
loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions("email");
// If using in a fragment
loginButton.setFragment(this);
// Other app specific specialization
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
Intent i = new Intent(this,Another.class);
startActivity(i);
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
答案 1 :(得分:0)
使用com.facebook.login.widget.LoginButton for facebook登录按钮小部件。
并在java文件中导入它们。
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;