如何使用Amazon AWS在Facebook中登录到关系数据库中存储用户信息 [英] How to store user information in relational database using Amazon AWS for Facebook Login in Android

查看:147
本文介绍了如何使用Amazon AWS在Facebook中登录到关系数据库中存储用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个Android应用程序,并开始运行Facebook登录。我接下来要做的是将用户信息存储在Amazon AWS中的关系数据库服务中。我在亚马逊和以前的研究中设立了一个实例,我的印象是需要创建一个用户池来存储用户信息,但是我不太确定是这样的,我不确定一旦设置,如何实际使用用户池。我也可以看到Cognito同步可以使用,但是再次将其与Facebook在Android上集成并不是我所知道的,也不能在线查找资源或信息。一旦用户通过Facebook登录,我想存储他们的姓名和电子邮件,并访问他们的朋友的列表。

I am currently developing an Android app and have a Facebook login up and running. What I am trying to do next is store the user information in a relation database service in Amazon AWS. I have set up an instance on Amazon and from previous research, I am under the impression a user pool needs to be created to store the user information, but 1. I am not quite sure this is the case and 2. I am not sure how to actually use the user pool once set up. I also see Cognito sync can be used, but again integrating this with Facebook on Android is not something I am aware of doing nor can I find the resources or information online for doing it. Once the user has logged in via Facebook, I would like to store their name and email and gain access to their friend's list.

我的下面的代码显示了我的Facebook login.java文件的主要部分:

My below code shows the main part of my Facebook login.java file:

if(AccessToken.getCurrentAccessToken() != null){
        RequestData();
        share.setVisibility(View.VISIBLE);
        details.setVisibility(View.VISIBLE);
        destinations.setVisibility(View.VISIBLE);
    }

    login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if(AccessToken.getCurrentAccessToken() != null) {
                share.setVisibility(View.INVISIBLE);
                details.setVisibility(View.INVISIBLE);
                destinations.setVisibility(View.INVISIBLE);
                profile.setProfileId(null);
            }
        }
    });

    share.setOnClickListener(
            new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ShareLinkContent content = new ShareLinkContent.Builder().build();
            shareDialog.show(content);

        }
    });

    destinations.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, SelectDestination.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);

        }
    });

    login.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {

            Intent intent = new Intent(MainActivity.this, SelectDestination.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);

            if(AccessToken.getCurrentAccessToken() != null){
                RequestData();
                share.setVisibility(View.VISIBLE);
                details.setVisibility(View.VISIBLE);
                destinations.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onCancel() {
            System.out.println("Cancelled");
        }

        @Override
        public void onError(FacebookException exception) {
            System.out.println("Cancelled");
        }
    });

}
public void RequestData(){
    GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(JSONObject object,GraphResponse response) {

            JSONObject json = response.getJSONObject();
            try {
                if(json != null){
                    String text = "<b>Name :</b> "+json.getString("name")+"<br><br><b>Email :</b> "+json.getString("email")+"<br><br><b>Profile link :</b> "+json.getString("link");
                    details_txt.setText(Html.fromHtml(text));
                    profile.setProfileId(json.getString("id"));
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,link,email,picture");
    request.setParameters(parameters);
    request.executeAsync();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

我已将以下内容添加到我的Build.app gradle文件中,因为我相信可能需要:

I have added the following to my Build.app gradle file as I believe they may be needed:

compile 'com.amazonaws:aws-android-sdk-ec2:2.+'
compile 'com.amazonaws:aws-android-sdk-core:2.+'
compile 'com.amazonaws:aws-android-sdk-cognito:2.+'
compile 'com.amazonaws:aws-android-sdk-s3:2.+'
compile 'com.amazonaws:aws-android-sdk-ddb:2.+'
compile 'com.amazonaws:aws-android-sdk-sdb:2.+'

我还将以下依赖关系添加到我的AndroidManifestxml中:

I also added the following dependencies to my AndroidManifestxml:

<dependencies>
    <dependency>
        <groupid>com.amazonaws</groupid>
        <artifactid>aws-android-sdk-core</artifactid>
        <version>[2.2.0, 2.3)</version>
    </dependency>
    <dependency>
        <groupid>com.amazonaws</groupid>
        <artifactid>aws-android-sdk-cognito</artifactid>
        <version>[2.2.0, 2.3)</version>
    </dependency>
    <dependency>
        <groupid>com.amazonaws</groupid>
        <artifactid>aws-android-sdk-mobileanalytics</artifactid>
        <version>[2.2.0, 2.3)</version>
    </dependency>
    <dependency>
        <groupid>com.amazonaws</groupid>
        <artifactid>aws-android-sdk-sqs</artifactid>
        <version>[2.2.0, 2.3)</version>
    </dependency>
    <dependency>
        <groupid>com.amazonaws</groupid>
        <artifactid>aws-android-sdk-ec2</artifactid>
        <version>[2.2.0, 2.3)</version>
    </dependency>
    <dependency>
        <groupid>com.amazonaws</groupid>
        <artifactid>aws-android-sdk-s3</artifactid>
        <version>[2.2.0, 2.3)</version>
    </dependency>
</dependencies>

任何人都可以提供有关如何做功能的信息吗?这是我应用程序的主要部分,它真的让我回来了。我真的很感激任何帮助。

Can anyone provide any information on how to do functionality please? It is a major part of my app and it is really holding me back. I would really appreciate it any help at all.

谢谢。

推荐答案

你不能直接从android处理关系数据库服务。您将需要某种Web服务器或lambda功能与rds通话,并使用查询输出回复您。

You cannot talk to a relational database service directly from android. You will need some sort of web server or lambda function to talk to the rds and respond you with the query output.

您可以在这里找到更多关于如何做的信息 http://docs.aws.amazon.com/lambda/latest /dg/vpc-rds.html

You can find more information on how to do that here http://docs.aws.amazon.com/lambda/latest/dg/vpc-rds.html

然后,您可以使用Android SDK的AWS SDK来调用已创建的lambda函数。

You can then use a AWS SDK for Android to invoke the lambda function that you have created.

这篇关于如何使用Amazon AWS在Facebook中登录到关系数据库中存储用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆