错误:com.facebook.FacebookException:无法为用户生成预览

时间:2014-04-03 05:51:21

标签: android facebook-graph-api facebook-opengraph

我在用户的墙上发布了一个自定义故事。为此,我在我的代码中创建了一个对象和动作。我已经从https://developers.facebook.com/docs/android/open-graph/链接完成了我的代码。我正在使用Facebook对话框用于发布自定义故事。

当开发人员使用他的Facebook帐户并在时间线上发布时,此代码工作正常..当开发人员在此应用程序中使用他的Facebook帐户时,此应用程序打开Facebook对话框发布自定义故事,但另一个人lo在这个应用程序中使用他/她的Facebook帐户,Facebook对话框出现并立即消失。并显示错误Error: com.facebook.FacebookException:无法为用户生成预览。

我想知道我的代码或任何其他原因是否有任何问题。我还在开发者account.i上注册了我的应用程序,使用以下代码执行此操作。任何知道或做过此事的人都请告诉我该怎么做。我将非常感谢你。我也想告诉我我正在使用Facebook sdk 3.7。

public class MainActivity extends Activity {
                    Button button1;
                    private static final String TAG = "MainActivity";
                    private UiLifecycleHelper uiHelper;
                    private static final List<String> PERMISSIONS = Arrays
                            .asList("publish_actions");
                    private static final String PENDING_PUBLISH_KEY = "pendingPublishReauthorization";
                    private ProgressDialog progressDialog;
                    private boolean pendingPublishReauthorization = false;

                    @Override
                    protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_main);

                        button1 = (Button) findViewById(R.id.button1);

                        uiHelper = new UiLifecycleHelper(this, callback);
                        uiHelper.onCreate(savedInstanceState);
                        Session session = Session.getActiveSession();
                        if (!session.isOpened() && !session.isClosed()) {
                            session.openForRead(new Session.OpenRequest(this).setPermissions(
                                    Arrays.asList("basic_info", "email","user_birthday","user_location","user_hometown","user_about_me","user_relationships")).setCallback(callback));
                            session.openForPublish(new Session.OpenRequest(this).setPermissions(
                                    Arrays.asList("publish_actions")).setCallback(callback));
                        } else {
                            Session.openActiveSession(this, true, callback);
                        }

                        button1.setOnClickListener(new OnClickListener() {

                            @SuppressWarnings("deprecation")
                            @Override
                            public void onClick(View v) {

                                OpenGraphObject meal = OpenGraphObject.Factory
                                        .createForPost("music.song");
                                meal.setProperty("title", "Competent Groove");
                                meal.setProperty("image",
                                        "http://example.com/cooking-app/images/buffalo-tacos.png");
                                meal.setProperty("url",
                                        "https://example.com/cooking-app/meal/Buffalo-Tacos.html");
                                meal.setProperty("description",
                                        "requested a hasher song at pizzahutt via Blureffect");

                                OpenGraphAction action = GraphObject.Factory
                                        .create(OpenGraphAction.class);
                                action.setProperty("song", meal);

                                FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(
                                        MainActivity.this, action, "blureffect_unique:request",
                                        "song").build();

                                uiHelper.trackPendingDialogCall(shareDialog.present());
                            }
                        });

                    }

                    @Override
                    public boolean onCreateOptionsMenu(Menu menu) {
                        // Inflate the menu; this adds items to the action bar if it is present.
                        getMenuInflater().inflate(R.menu.main, menu);
                        return true;
                    }

                    private Session.StatusCallback callback = new Session.StatusCallback() {
                        @Override
                        public void call(Session session, SessionState state,
                                Exception exception) {
                            onSessionStateChange(session, state, exception);

                        }
                    };

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

                        uiHelper.onActivityResult(requestCode, resultCode, data,
                                new FacebookDialog.Callback() {
                                    @Override
                                    public void onError(FacebookDialog.PendingCall pendingCall,
                                            Exception error, Bundle data) {
                                        Log.e("Activity",
                                                String.format("Error: %s", error.toString()));
                                    }

                                    @Override
                                    public void onComplete(
                                            FacebookDialog.PendingCall pendingCall, Bundle data) {
                                        Log.i("Activity", "Success!");
                                        button1.setEnabled(true);

                                    }
                                });
                    }

                    @SuppressWarnings("deprecation")
                    private void onSessionStateChange(Session session, SessionState state,
                            Exception exception) {
                        if (session != null && session.isOpened()) {
                            Log.d("DEBUG", "facebook session is open ");
                            // make request to the /me API
                            Request.executeMeRequestAsync(session,
                                    new Request.GraphUserCallback() {
                                        // callback after Graph API response with user object

                                        @Override
                                        public void onCompleted(GraphUser user,
                                                Response response) {
                                            if (user != null) {

                                                  button1.setEnabled(true);

                                                  Log.i("Birthday", ""+user.getBirthday());
                                                  Log.i("LastName", ""+user.getLastName());
                                                  Log.i("FirstName", ""+user.getFirstName());
                                                  Log.i("getId", ""+user.getId());
                                                  Log.i("email", ""+user.asMap().get("email"));
                                                  Log.i("gender", ""+user.asMap().get("gender"));
                                                  Log.i("Birthday", ""+user.getBirthday());
                                                  Log.i("city", ""+user.getLocation().getProperty("name").toString());

                                            }

                                        }
                                    });
                        }
                    }

                    @Override
                    protected void onResume() {
                        super.onResume();
                        uiHelper.onResume();
                    }

                    @Override
                    protected void onSaveInstanceState(Bundle outState) {
                        super.onSaveInstanceState(outState);
                        uiHelper.onSaveInstanceState(outState);
                    }

                    @Override
                    public void onPause() {
                        super.onPause();
                        uiHelper.onPause();
                    }

                    @Override
                    public void onDestroy() {
                        super.onDestroy();
                        uiHelper.onDestroy();
                    }

                    /*
                     * Helper method to check a collection for a string.
                     */
                    @SuppressWarnings("unused")
                    private boolean isSubsetOf(Collection<String> subset,
                            Collection<String> superset) {
                        for (String string : subset) {
                            if (!superset.contains(string)) {
                                return false;
                            }
                        }
                        return true;
                    }

                    /*
                     * Helper method to dismiss the progress dialog.
                     */
                    @SuppressWarnings("unused")
                    private void dismissProgressDialog() {
                        // Dismiss the progress dialog
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                    }
                }

1 个答案:

答案 0 :(得分:3)

enter image description here 用于生成散列密钥

private PackageInfo INFO = null; //global declaration
    public void generateHashKeyForFacebook(Context context) throws Exception {
            try {
                INFO = context.getPackageManager().getPackageInfo("com.bito1.Shoplu", PackageManager.GET_SIGNATURES);
                if (INFO == null) {
                    Toast.makeText(context.getApplicationContext(), "Invalid Package Name / Package not found", Toast.LENGTH_LONG).show();
                    return;
                }
                for (Signature signature : INFO.signatures) {
                    MessageDigest _md = MessageDigest.getInstance("SHA");
                    _md.update(signature.toByteArray());
                    Log.d("KeyHash: =>", Base64.encodeToString(_md.digest(), Base64.DEFAULT));
                }
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
        }