自动发布到Facebook墙

时间:2013-12-10 11:05:33

标签: android facebook

我的代码如下: -

public void publishFeedDialog(final Activity activity, final FacebookLogin fl) 
{
    Session session = Session.getActiveSession();

    //if session is not empty and it is opened
    if (session != null && session.isOpened()){

        // Check for publish permissions    
        List<String> permissions = session.getPermissions();
        if (!isSubsetOf(PERMISSIONS, permissions)) {
            pendingPublishReauthorization = true;
            Session.NewPermissionsRequest newPermissionsRequest = new Session
                    .NewPermissionsRequest(activity, PERMISSIONS);
            session.requestNewPublishPermissions(newPermissionsRequest);
            return;
        }
            Bundle params = new Bundle();

            params.putString("name", "test");
            params.putString("message", "MESSAGE TO GO WITH THE IMAGE");
            params.putString("description", "test test test");

        WebDialog feedDialog = (
                new WebDialog.FeedDialogBuilder(activity,
                        Session.getActiveSession(),
                        params))
                        .setOnCompleteListener(new OnCompleteListener() {

                            @Override
                            public void onComplete(Bundle values,
                                    FacebookException error) {
                                if (error == null) {
                                    // When the story is posted, echo the success
                                    // and the post Id.
                                    final String postId = values.getString("post_id");
                                    if (postId != null) {

                                        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                                        builder.setTitle("POST")
                                        .setMessage("")
                                        .setCancelable(false)
                                        .setNegativeButton("OK",
                                                new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int id) {
                                                dialog.cancel();
                                            }
                                        });
                                        AlertDialog alert = builder.create();
                                        alert.show();
                                    } else {
                                        // User clicked the Cancel button
                                        Toast.makeText(activity, 
                                                "Publish cancelled", 
                                                Toast.LENGTH_SHORT).show();
                                    }
                                } else if (error instanceof FacebookOperationCanceledException) {
                                    // User clicked the "x" button
                                    Toast.makeText(activity, 
                                            "Publish cancelled", 
                                            Toast.LENGTH_SHORT).show();
                                } else {
                                    // Generic, ex: network error
                                    Toast.makeText(activity, 
                                            "Error posting story", 
                                            Toast.LENGTH_SHORT).show();
                                }
                            }

                        })
                        .build();
        feedDialog.show();
    }
    else
    {
        // login with facebook if no session is available

    }
}   

我尝试将短信/描述发送到Facebook帖子但失败了。我也有自动分享的问题。目前我需要点击发布按钮才能将内容发布到我的脸书。任何帮助都会受到欢迎。

先谢谢。

2 个答案:

答案 0 :(得分:1)

使用以下内容可以帮助您进行社交集成。 https://code.google.com/p/socialauth/

答案 1 :(得分:1)

Feed对话框不支持“消息”字段。

请参阅此处的Feed对话文档:https://developers.facebook.com/docs/reference/dialogs/feed/