Может кто-нибудь помочь мне, как хранить профиль пользователя facebook для анализа библиотеки? Я делаю приложение для Android. Я хочу, чтобы после входа в систему с помощью facebook пользовательская информация (например, электронная почта, имя, пол) хранила для анализа библиотеки, а затем приложение показывало новую активность. Но мое приложение застряло в регистрации в диалоговом окне после аутентификации в facebook и ничего не хранило для анализа библиотеки. Кто-нибудь может мне помочь? Thankyou оченьХранение данных для входа в android facebook для разбора
Вот это MainActivity.java
package com.contoh.mutia.persistentlogin;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.parse.LogInCallback;
import com.parse.ParseException;
import com.parse.ParseFacebookUtils;
import com.parse.ParseUser;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends Activity {
public Dialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Check if there is a currently logged in user
// and they are linked to a Facebook account.
ParseUser currentUser = ParseUser.getCurrentUser();
if ((currentUser != null) && ParseFacebookUtils.isLinked(currentUser)) {
// Go to the user info activity
showwelkamActivity();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void onLoginClick(View v) {
MainActivity.this.progressDialog = ProgressDialog.show(
MainActivity.this, "", "Logging in...", true);
List<String> permissions = Arrays.asList("public_profile", "email");
ParseFacebookUtils.logIn(permissions, this, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
MainActivity.this.progressDialog.dismiss();
if (user == null) {
Log.d(IsianParse.TAG,
"Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew()) {
Log.d(IsianParse.TAG,
"User signed up and logged in through Facebook!");
showwelkamActivity();
} else {
Log.d(IsianParse.TAG,
"User logged in through Facebook!");
showwelkamActivity();
}
}
});
}
private void showwelkamActivity() {
Intent intent = new Intent(this, welkampage.class);
startActivity(intent);
}
}
Здесь welkampage.java новый вид деятельности, который я хочу показать после Войти facebook успеха
package com.contoh.mutia.persistentlogin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.facebook.FacebookRequestError;
import com.facebook.LoginActivity;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.model.GraphUser;
import com.parse.ParseFacebookUtils;
import com.parse.ParseUser;
import org.json.JSONException;
import org.json.JSONObject;
public class welkampage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welkampage);
// Fetch Facebook user info if the session is active
Session session = ParseFacebookUtils.getSession();
if (session != null && session.isOpened()) {
makeMeRequest();
}
}
@Override
public void onResume() {
super.onResume();
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
// Check if the user is currently logged
// and show any cached content
showwelkamActivity();
} else {
// If the user is not logged in, go to the
// activity showing the login view.
startLoginActivity();
}
}
private void showwelkamActivity() {
Intent intent = new Intent(this, welkampage.class);
startActivity(intent);
}
private void makeMeRequest() {
Request request = Request.newMeRequest(ParseFacebookUtils.getSession(),
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
// Create a JSON object to hold the profile info
JSONObject userProfile = new JSONObject();
try {
// Populate the JSON object
userProfile.put("facebookId", user.getId());
userProfile.put("name", user.getName());
if (user.getProperty("gender") != null) {
userProfile.put("gender", user.getProperty("gender"));
}
if (user.getProperty("email") != null) {
userProfile.put("email", user.getProperty("email"));
}
// Save the user profile info in a user property
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.put("profile", userProfile);
currentUser.saveInBackground();
} catch (JSONException e) {
Log.d(IsianParse.TAG, "Error parsing returned user data. " + e);
}
} else if (response.getError() != null) {
if ((response.getError().getCategory() == FacebookRequestError.Category.AUTHENTICATION_RETRY) ||
(response.getError().getCategory() == FacebookRequestError.Category.AUTHENTICATION_REOPEN_SESSION)) {
Log.d(IsianParse.TAG, "The facebook session was invalidated." + response.getError());
logout();
} else {
Log.d(IsianParse.TAG,
"Some other error: " + response.getError());
}
}
}
}
);
request.executeAsync();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_welkampage, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void onLogoutClick(View v) {
logout();
}
private void logout() {
// Log the user out
ParseUser.logOut();
// Go to the login view
startLoginActivity();
}
private void startLoginActivity() {
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
Вот Isianparse.java
package com.contoh.mutia.persistentlogin;
import android.app.Application;
import com.parse.Parse;
public class IsianParse extends Application {
static final String TAG = "MyApp";
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this,"appid","mykey");
}}
Кстати, никогда не публикуйте свои синтаксические ключи в вопросе. – Akil
@Shumimura вы застряли во входе в систему или в получении информации и хранении ее в DB синтаксического анализа? – Akil
Также разместите свою копию onActivityResult в welkampage.java @shumimura – Akil