开发者

Facebook JS API: How to get FB.Connect.streamPublish to use auto_publish

开发者 https://www.devze.com 2022-12-22 23:06 出处:网络
I\'m trying to publish stuff to someone\'s wall. It works, but I\'m also trying to use the auto_publish feature so the user will only get one popup granting the publish_stream extended permission.

I'm trying to publish stuff to someone's wall.

It works, but I'm also trying to use the auto_publish feature so the user will only get one popup granting the publish_stream extended permission.

So I set streamPubli开发者_运维百科sh's auto_publish to true, but I still get the popup asking me if I want to publish and/or edit the message.

What am I doing wrong?

Here's what I'm running:

FB.ensureInit(function () {
    FB.Facebook.get_sessionState().waitUntilReady(function() {
        FB.Connect.showPermissionDialog("publish_stream", function(perms) {
            if (perms == "publish_stream") {
                FB.Facebook.apiClient.friends_get(null, function(result) {
                    var markup = "";

                    var targets = result;
                    targets = [testFriendsIDForTesting];

                    var attachment = {
                        name: "Blablabla",
                        href: window.location.href,
                        description: "description",
                        caption: "caption"
                    };

                    var actionLinks = [{
                        text: "View",
                        href: window.location.href
                    }];

                    var num_targets = targets.length;
                    for (var i=0; i<num_targets; i++) {
                        var fId = targets[i];
                        FB.Connect.streamPublish("none", attachment, actionLinks, fId, "none", null, true);
                    }

                });
            }
        });

    });
});


Came across this thread as im having the same issue, which i solved (without having to use the other apiClient call).

You are right in your answer above, in that FB are not setting the autoPublish settings properly.

The workaround is to make a call to FB.Connect.forceSessionRefresh before attempting to publish.

My code before:

function fbPublish() {{
                FB.ensureInit(function() {{
                        FB.Connect.streamPublish('{0}', {1}, {2}, null, 'Anything else you would like to add?', fbPublishCallback, true, null);
                    }});
            }}

Code now:

function fbPublish() {{
                FB.ensureInit(function() {{
                    FB.Connect.forceSessionRefresh(function() {{
                        FB.Connect.streamPublish('{0}', {1}, {2}, null, 'Anything else you would like to add?', fbPublishCallback, true, null);
                    }});
                }});
            }}

The only reason im using this "old" JavaScript method is because there is a current bug with the Graph API where you cannot post action links.

I have no idea what kind of developers they have over at Facebook, because the issues i have run into have been disgraceful (this, Graph API not allowing action links, '' instead of null causing "Application Server Error", etc).

Hope this helps someone else out.


The problem stems from the last parameter your passing as false. This is the auto_publish bool, so even with the permissions granted with this set to false it will prompt the user if they want to publish it or not.

// Set auto publish to true
FB.Connect.streamPublish("none", attachment, actionLinks, fId, "none", null, true);


I'm still unsure why this doesn't work as expected, but I've checked the FB JS code and it's failing to set my user autoPublish settings properly in it's userInfo object.

So I've worked around this by calling stream.publish via:

FB.Facebook.apiClient.callMethod("stream.publish", c, new FB.ImmediateSequencer(function(n,m){
0

精彩评论

暂无评论...
验证码 换一张
取 消