Question

I have a function that is called on a click. I want to have a dialog box open that allows a user to publish an image to their FB wall. I am using the Javascript SDK. When this runs, however, nothing happens. Any ideas?:

window.fbAsyncInit = function () {
    FB.init({ appId: '***********', cookie: true, xfbml: true, oauth: true });
        // *** here is my code ***
        if (typeof facebookInit == 'function') {
            facebookInit();
        }
    };

    (function(d){
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
    }(document));

/* make the API call */
function facebookInit() {
    FB.api(
        "/me/photos",
        "POST",
        {
            "object": {
                "url": "https://graph.facebook.com/*******/picture?width=720&height=720"
            }
        },
        function (response) {
            if (response && !response.error) {
                window.location = "http://url.com";
            }
        }
     );
}
Était-ce utile?

La solution

You are publishing photo using the Graph API, not the dialog.

In fact you cannot post a photo using a dialog, that's the correct way of doing which you are following.

Another thing, instead of-

"object": {
   "url": "https://graph.facebook.com/*******/picture?width=720&height=720"
}

simply send the url parameter. The object jey is not required.

And you can always check the response/error in console.log(response)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top