2

アプリでFBConnectを使用しようとしていますが、エミュレータとGalaxy Nexusでのデバッグはすべて正常に機能しますが、GooglePlayにアップロードすると機能しなくなります。

Playからダウンロードしてアプリをインストールすると、facebook.authorize関数がDialogErrorを返します(インストールがeclipseで行われた場合にのみ、logcatを表示できるため、どのエラーかわかりません)。そして、それは私がFacebookアプリをインストールしている場合にのみ起こります。だから私がfbアプリをアンインストールするとそれはうまくいきます...

コンピューターでFacebookSDKを準備しているときに、間違った構成を行った可能性がありますか?以下にすべてのコードを貼り付けましたが、ログがありません...

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)");

}

}
4

1 に答える 1

4

配布用のアプリケーションに署名したときに、別のキーストアファイルを使用しました。

これを修正するには、同じコマンドを実行しますが、キーストアのエイリアスと場所を、配布に使用したキーストアファイルに変更します

keytool -exportcert -alias YOUR_ALIAS_HERE -keystore ~/path/to/yourapp.keystore | openssl sha1 -binary | openssl base64

結果の文字列をFacebookアプリのダッシュボード設定の[Androidキーハッシュ]セクションに貼り付けます。

于 2012-08-20T18:54:54.327 に答える