简体   繁体   English

Android:在自定义应用中通过Facebook登录验证用户

[英]Android : Authenticate user via facebook login in custom app

I am developing an application in which i want to login via facebook. 我正在开发一个要通过Facebook登录的应用程序。 What I done is: 我所做的是:

After splash screen a login screen is there on which user name and password edit text are there. 初始屏幕后,出现登录屏幕,上面有用户名和密码编辑文本。 After entering the credential on clicking on face book login button the user should authenticate from face book in background. 在单击脸书登录按钮输入凭据后,用户应在后台从脸书进行身份验证。 If the user is authenticated then he directly goes on next activity else toast message should pop up. 如果用户通过了身份验证,那么他将直接进行下一个活动,否则将弹出敬酒消息。

I had done some code in .java as : 我在.java中做了一些代码,如下所示:

public class LoginScreenActivity extends Activity {
/** Global Variable Declaration. */
int nextMoveFlage = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_layout);
            // 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.executeMeRequestAsync(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.textview_hello);
                            welcome.setText("Hello "+ user.getName() + "!");
                            //Intent intent = new Intent(LoginScreenActivity.this,NextScreen.class);
                            //startActivity(intent);
                        }
                    }
                });
            }
        }
    });
}

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode,resultCode, data);
    }
}

I also created app in my face book console and added all information such as Key Hash, Package Name, etc. And copy that app id in my String.XML file. 我还在脸书控制台中创建了应用程序,并添加了所有信息,例如密钥哈希,程序包名称等 。并将该应用程序ID复制到我的String.XML文件中。

Added metadata in manifest file for app id. 在清单文件中为应用程序ID添加了元数据。

The issue is that : 问题是:

  1. I am not able to move on next activity after login as how to move or where to write intent code. 登录后,我无法继续进行下一个活动,如如何移动或在何处编写意图代码。

  2. Is the face app (SDK) is necessary to run my app. 是面部应用程序(SDK)是运行我的应用程序所必需的。 If any one is not having facebook SDK than what is the solution. 如果没有人使用Facebook SDK,那么解决方案是什么。

  3. Some times i got an error as remote_app_id does not match stored id But i copied the app id from face book console itself. 有时我会出错,因为remote_app_id与存储的ID不匹配,但是我从脸书控制台本身复制了应用ID。

Please guide me on my issues and give your valuable suggetions. 请指导我解决我的问题,并提出宝贵的建议。

  1. You should put the intent to start the next activity in your session status callback (inside the if(Session.isOpened()) check, where you're currently executing a "me" request. 您应该将意图在会话状态回调中(在if(Session.isOpened())检查中,当前正在执行“我”请求的地方)开始下一个活动。

  2. The SDK is necessary to run your app, but not the Facebook app. SDK是运行您的应用程序所必需的,而不是Facebook应用程序。 The SDK is included (and bundled) with your apk, the Facebook app is a separate apk, and is not required for log in with Facebook. 该SDK包含(并捆绑)在您的apk中,Facebook应用是一个单独的apk,通过Facebook登录不需要。

  3. If you get that error, that means you don't have the right key hashes in your settings. 如果收到该错误,则意味着您的设置中没有正确的键哈希。 Did you sign using a different keystore? 您是否使用其他密钥库签名?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM