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.
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);
}
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.+'
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.
Thank you.