Android Facebook Connect在上传到google play后停止工作
我尝试在我的应用程序上使用FB Connect,在模拟器中一切正常,在Galaxy Nexus中调试,但在上传到google play后,它就停止工作了 如果我从Play下载应用程序,我的facebook.authorize函数会返回一个DialogError,我不知道是什么错误,因为我只能在使用eclipse进行安装时查看logcat。只有在我安装了facebook应用程序的情况下才会发生这种情况。所以,当我卸载fb应用程序时,它工作得很好 可能是我在电脑上准备facebook SDK时配置错误?我在下面粘贴了所有代码,但没有任何日志Android Facebook Connect在上传到google play后停止工作,android,facebook,google-play,Android,Facebook,Google Play,我尝试在我的应用程序上使用FB Connect,在模拟器中一切正常,在Galaxy Nexus中调试,但在上传到google play后,它就停止工作了 如果我从Play下载应用程序,我的facebook.authorize函数会返回一个DialogError,我不知道是什么错误,因为我只能在使用eclipse进行安装时查看logcat。只有在我安装了facebook应用程序的情况下才会发生这种情况。所以,当我卸载fb应用程序时,它工作得很好 可能是我在电脑上准备facebook SDK时配置错
public class FacebookConnectActivity extends Activity {
private static final String TAG_JSON = "json";
static Facebook facebook = new Facebook("11111111111111");
AsyncFacebookRunner mAsyncRunner;
private static SharedPreferences mPrefs;
JSONObject json = null;
Context ctx = this;
boolean callback = false;
private static Context staticContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resgatar_produto_layout);
FacebookConnectActivity.staticContext = getApplicationContext();
Log.e("FacebookConnect", "Activity Started");
mPrefs = getSharedPreferences("PREFS_LOGIN", MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
Log.e("FacebookConnect",
"Access Token retrieved from SharedPreferences");
}
if (expires != 0) {
facebook.setAccessExpires(expires);
Log.e("FacebookConnect",
"Access Expires retrieved from SharedPreferences");
}
if (!facebook.isSessionValid()) {
facebook.authorize(this, new String[] { "email", "user_photos",
"user_birthday", "user_hometown", "user_relationships",
"user_location", "user_work_history", "publish_actions" },
new DialogListener() {
@Override
public void onComplete(Bundle values) {
Log.e("FacebookConnect", "User authorized");
Log.e("FacebookConnect",
"onComplete called at facebook.authorize");
Log.e("FacebookConnect", "Access Token: "
+ facebook.getAccessToken().toString());
try {
mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me",
new SampleRequestListener());
Log.e("FacebookConnect",
"AsyncFacebookRunner request started (facebook.authorize.onComplete)");
Bundle params = new Bundle();
params.putString("link",
"https://apps.facebook.com/qranio_game/");
params.putString("picture", "http://www.qranio.com/site/images/logo_qranio_facebook.png");
int count = 0;
while (json == null && count<20){
Log.e("FacebookConnect",
"Waiting for json (facebook.authorize.onComplete)");
waiting(1000);
count++;
}
if (!(count<20)){
noConnectionAlert();
}
String usuario = json.getString("first_name");
params.putString("name", usuario+" está jogando Qranio para Android");
params.putString("caption", "Qranio - Making Learning Fun");
params.putString("description", "O Qranio é uma plataforma online que propicia o Saber. Você joga, " +
"aprende, acumula Qi$ e troca por prêmios incríveis! Venha jogar também!");
//JSONArray fbArr = new JSONArray("{\"name\":\"Jogar\",\"link\":\"https://apps.facebook.com/qranio_game/\"}");
params.putString("actions", "{\"name\":\"Jogar\",\"link\":\"https://apps.facebook.com/qranio_game/\"}");
params.putString("display", "touch");
facebook.dialog(ctx, "feed", params,
new SampleDialogListener());
Log.e("FacebookConnect",
"Post on Wall Dialog called (facebook.authorize.onComplete)");
// facebook.
// if (facebook.isSessionValid()){
// }else{
// Log.e("FacebookConnect",
// "Invalid facebook session while trying to fetch user data");
// }
} catch (FacebookError fbe) {
Log.e("FacebookConnect",
"facebook.authorize FacebookError "
+ fbe.toString());
} catch (Exception e) {
Log.e("FacebookConnect",
"facebook.authorize Exception "
+ e.toString());
}
}
@Override
public void onFacebookError(FacebookError error) {
Log.e("FacebookConnect",
"FacebookError authorizing: "
+ error.toString());
final AlertDialog alertDialog = new AlertDialog.Builder(
FacebookConnectActivity.this).create();
alertDialog.setTitle("Erro");
alertDialog
.setMessage("Ocorreu um erro com o Facebook, por favor tente novamente.");
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {
alertDialog.dismiss();
finish();
}
});
alertDialog.show();
}
@Override
public void onError(DialogError e) {
//Here is where I'm getting the error when downloaded from Play
Log.e("FacebookConnect",
"Error authorizing: " + e.toString());
final AlertDialog alertDialog = new AlertDialog.Builder(
FacebookConnectActivity.this).create();
alertDialog.setTitle("Erro");
alertDialog
.setMessage("Erro ao tentar conectar com o facebook, tente novamente.");
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {
alertDialog.dismiss();
finish();
}
});
alertDialog.show();
}
@Override
public void onCancel() {
Log.e("FacebookConnect", "Autorizing canceled");
finish();
}
});
} else {
mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me", new SampleRequestListener());
Log.e("FacebookConnect",
"Valid session found, AsyncFacebookRunner request started");
startDataProcess();
}
}
public void noConnectionAlert(){
final AlertDialog alertDialog = new AlertDialog.Builder(
FacebookConnectActivity.this).create();
alertDialog.setTitle("Erro");
alertDialog
.setMessage("Verifique sua conexão com a internet e tente novamente.");
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {
alertDialog.dismiss();
finish();
}
});
alertDialog.show();
}
public static void waiting (int n){
long t0, t1;
t0 = System.currentTimeMillis();
do{
t1 = System.currentTimeMillis();
}
while (t1 - t0 < n);
}
public static void logoutFB() {
if (facebook.isSessionValid()) {
Log.e("AndroidDashboarDesign",
"Valid FB session found, logging out");
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.logout(staticContext, new BaseRequestListener() {
@Override
public void onComplete(String response, Object state) {
Log.e("AndroidDashboarDesign", "Complete FB logout");
}
@Override
public void onIOException(IOException e, Object state) {
Log.e("AndroidDashboarDesign",
"(logout) IOException: " + e.getMessage());
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
Log.e("AndroidDashboarDesign",
"(logout) FileNotFoundException: " + e.getMessage());
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
Log.e("AndroidDashboarDesign",
"(logout) MalFormedURLException: " + e.getMessage());
}
@Override
public void onFacebookError(FacebookError e, Object state) {
Log.e("AndroidDashboarDesign", "(logout) FacebookError: "
+ e.getMessage());
}
});
}
}
public void startDataProcess() {
int count = 0;
while (json == null && count<20){
Log.e("FacebookConnect",
"Waiting for json (Valid session found)");
waiting(1000);
count++;
}
if (!(count<20)){
noConnectionAlert();
}else{
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
Log.e("FacebookConnect", "startDataProcess() executed");
Intent a = new Intent(FacebookConnectActivity.this,
FacebookDataProcess.class);
a.putExtra(TAG_JSON, json.toString());
startActivity(a);
finish();
}
}
public class SampleDialogListener extends BaseDialogListener {
public void onComplete(Bundle values) {
Log.e("FacebookConnect", "SampleDialogListener complete");
final String postId = values.getString("post_id");
if (postId != null) {
Log.e("FacebookConnect",
"(SampleDialogListener) Dialog Success! post_id="
+ postId);
//mAsyncRunner.request(postId, new WallPostRequestListener());
//Log.e("FacebookConnect", "WallPostRequestListener started");
Toast.makeText(FacebookConnectActivity.this, "Mensagem postada com sucesso!", Toast.LENGTH_LONG).show();
startDataProcess();
} else {
Log.e("FacebookConnect",
"(SampleDialogListener) No wall post made, maybe canceled by user."); // Usuario
// clicou
// em
// Cancelar
startDataProcess();
}
}
public void onError(DialogError e) {
Log.e("FacebookConnect",
"Error authorizing: " + e.toString());
final AlertDialog alertDialog = new AlertDialog.Builder(
FacebookConnectActivity.this).create();
alertDialog.setTitle("Erro");
alertDialog
.setMessage("Erro ao tentar conectar com o facebook, não foi possível publicar em seu mural.");
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {
startDataProcess();
alertDialog.dismiss();
}
});
alertDialog.show();
}
public void onCancel() { // Usuario clicou no X do dialog
Log.e("FacebookConnect", "Post to Wall Canceled with \"X\" button");
startDataProcess();
}
}
public class WallPostRequestListener extends BaseRequestListener {
public void onComplete(final String response, final Object state) {
Log.e("FacebookConnect", "WallPostRequestListener complete");
Log.e("FacebookConnect", "(WallPostRequestListener) Got response: "
+ response);
String message = "<empty>";
try {
JSONObject json = Util.parseJson(response);
message = json.getString("message");
} catch (JSONException e) {
Log.e("FacebookConnect",
"(WallPostRequestListener) JSON Error in response: "
+ e.toString());
} catch (FacebookError e) {
Log.e("FacebookConnect",
"(WallPostRequestListener) Facebook Error: "
+ e.getMessage());
// Toast.makeText(ctx, "Erro ao postar no Facebook.",
// Toast.LENGTH_LONG).show();
}
startDataProcess();
}
}
public class SampleRequestListener extends BaseRequestListener {
public void onComplete(final String response, final Object state) {
try {
// process the response here: executed in background thread
Log.e("FacebookConnect", "SampleRequestListener complete");
Log.e("SampleRequestListener",
"Response: " + response.toString());
json = Util.parseJson(response);
Log.e("FacebookConnect", "JSON: " + json.toString());
// postOnWall();
// startDataProcess();
// then post the processed result back to the UI thread
// if we do not do this, an runtime exception will be generated
// e.g. "CalledFromWrongThreadException: Only the original
// thread that created a view hierarchy can touch its views."
} catch (JSONException e) {
Log.e("FacebookConnect",
"JSON Error in response (SampleRequestListener): "
+ e.getMessage());
} catch (FacebookError e) {
Log.e("FacebookConnect",
"Facebook Error at SampleRequestListener: "
+ e.getMessage());
}
}
}
public void postOnWall() {
Looper.prepare();
Bundle params = new Bundle();
params.putString("link", "www.qranio.com");
facebook.dialog(ctx, "feed", params, new SampleDialogListener());
Log.e("FacebookConnect", "SampleDialogListener started");
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
callback = true;
Log.e("FacebookConnect",
"Authentication authorizeCallback called (onActivityResult)");
}
}
您在为分发应用程序签名时使用了不同的密钥库文件 要解决此问题,请运行相同的命令,但将密钥库的别名和位置更改为用于分发的密钥库文件 keytool-exportcert-alias YOUR_alias_HERE-keystore~/path/to/yourapp.keystore | openssl sha1-binary | openssl base64
并将生成的字符串粘贴到Facebook应用程序的“安卓密钥哈希”部分下的仪表板设置中。您在为分发应用程序签名时使用了不同的密钥库文件 要解决此问题,请运行相同的命令,但将密钥库的别名和位置更改为用于分发的密钥库文件 keytool-exportcert-alias YOUR_alias_HERE-keystore~/path/to/yourapp.keystore | openssl sha1-binary | openssl base64
并将生成的字符串粘贴到你的Facebook应用程序的“安卓密钥哈希”部分下的仪表板设置中。你是否为你的应用程序生成了第二个应用程序密钥?我不确定,你是指我粘贴在我的Facebook应用程序设置上的应用程序签名?如果你转到你的Facebook开发者页面,在“应用程序”下。您将看到Android密钥哈希部分。当您第一次创建应用程序时,您需要生成一个应用程序,以便Facebook使用您的应用程序。现在你已经发布了你的应用程序,你需要一个不是调试密钥的新密钥。请参阅下面关于如何生成它的内容。您是否为您的应用程序生成了第二个应用程序密钥?我不确定,您是指我粘贴在我的Facebook应用程序设置上的应用程序签名吗?如果您转到您的Facebook开发者页面,请在“应用程序”下。您将看到Android密钥哈希部分。当您第一次创建应用程序时,您需要生成一个应用程序,以便Facebook使用您的应用程序。现在你已经发布了你的应用程序,你需要一个不是调试密钥的新密钥。请参阅下面关于如何生成它的内容。自从我第一次将它上传到Google Play之后,我使用的是相同的密钥库。此外,MOTODEV不允许我使用不同的密钥库导出我的应用程序我记不起密钥库的密码,所以我尝试使用新的密钥库。。。但我会尝试你的命令并将结果发布到这里,我已经做到了,但是现在即使在从motodev调试时,我也会得到一个对话框错误,说不可能稳定安全连接。我可能用keytool得到了一个错误的密钥散列,嗯?使用了debug.keystore和pass:android,正如教程中所说,我不确定这是否与密钥散列问题有关。如果您仍然处于开发模式,并且正在构建eclipse,那么您将使用Android提供的默认调试密钥库。如果您签署应用程序以将应用程序分发到市场等,那么您将使用自己的私有密钥库。确保您正在使用的密钥存储在仪表板上。一旦您完全确定您已经正确地完成了,那么您遇到的任何其他问题都应该与密钥散列无关。确保在运行命令时,它也会提示输入pw。我已经上传了一个新版本,其中在屏幕上显示了哈希不匹配错误,并且我得到了一个与我使用的哈希键不同的哈希键。我只是将其粘贴到我的fb应用程序配置中。非常感谢,我被这件事烦了好几个星期了!自从我第一次将密钥库上传到GooglePlay之后,我就一直在使用相同的密钥库。此外,MOTODEV不允许我使用不同的密钥库导出我的应用程序我记不起密钥库的密码,所以我尝试使用新的密钥库。。。但我会尝试你的命令并将结果发布到这里,我已经做到了,但是现在即使在从motodev调试时,我也会得到一个对话框错误,说不可能稳定安全连接。我可能用keytool得到了一个错误的密钥散列,嗯?使用了debug.keystore和pass:android,正如教程中所说,我不确定这是否与密钥散列问题有关。如果您仍然处于开发模式,并且正在构建eclipse,那么您将使用Android提供的默认调试密钥库。如果您签署应用程序以将应用程序分发到市场等,那么您将使用自己的私有密钥库。确保您正在使用的密钥存储在仪表板上。一旦你完全确定你做得正确,那么任何
您遇到的其他问题应该与密钥哈希无关。确保在运行命令时,它也会提示输入pw。我已经上传了一个新版本,其中在屏幕上显示了哈希不匹配错误,并且我得到了一个与我使用的哈希键不同的哈希键。我只是将其粘贴到我的fb应用程序配置中。非常感谢,我被这件事烦了好几个星期了!