0

如何使用已安装的 Facebook 应用程序以静默方式授权发布消息?我的意思是我已经看到了很多带有授权对话框的例子,但是是否可以使用已安装的 facebook 应用程序来做到这一点?

4

1 回答 1

0

好的,似乎这是一个错误或不知道是什么。这对我有用:

public void loginToFacebook() {
mPrefs = getPreferences(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);
}

if (expires != 0) {
    facebook.setAccessExpires(expires);
}

if (!facebook.isSessionValid()) {
    facebook.authorize(this,
            new String[] { "email", "publish_stream" },
            new DialogListener() {

                @Override
                public void onCancel() {
                    // Function to handle cancel event
                }

                @Override
                public void onComplete(Bundle values) {
                    // Function to handle complete event
                    // Edit Preferences and update facebook acess_token
                    SharedPreferences.Editor editor = mPrefs.edit();
                    editor.putString("access_token",
                            facebook.getAccessToken());
                    editor.putLong("access_expires",
                            facebook.getAccessExpires());
                    editor.commit();
                }

                @Override
                public void onError(DialogError error) {
                    // Function to handle error

                }

                @Override
                public void onFacebookError(FacebookError fberror) {
                    // Function to handle Facebook errors

                }

            });
}
}

从这里:http ://www.androidhive.info/2012/03/android-facebook-connect-tutorial/

于 2013-01-16T20:59:30.703 回答