简体   繁体   中英

PHP: how to upload a photo created in facebook app to users wall

I have a facebook app, where users can give instagram like effects to their image. http://instakilo.herokuapp.com/
when a image filter is added a download link will appear at the bottom, when clicked on that link, source of that edited image is created and added to the "href" attribute of the download link, and image is downloaded. now I want instead of downloading the image, I want to post that image to the users wall with some caption.

i searched few tutorials but they were showing uploading a pic via HTML form, where user selects image from their hard drive and post it, but here I have source of that image, in javascript variable. as you can see on my app in script.js file the following code at the end of script.js

function showDownload(canvas){


    downloadImage.off('click').click(function(){

        // When the download link is clicked, get the
        // DataURL of the image and set it as href:

        var url = canvas.toDataURL("image/png;base64;");
        downloadImage.attr('href', url);
        $.ajax({

                        type: "POST",
                        url: "http://instakilo.herokuapp.com/process.php",
                        data: {'data':url},
                        success: function(){alert('Posted');},
                        error:function(){alert('error');}
                    });



    }).fadeIn();
            downloadImage.css("display","inline-block");  

}

In url variable the image source is stored. As you can see I tried to POST it using ajax to process.php but it doesn't seem to be working.

How can I achieve this ?

To post photos from a URL use url and the me/photos endpoint

var params = {};
params['message'] = 'The message';;
params['url'] = url;


FB.api('/me/photos', 'post', params, function(response) {
    if (!response || response.error) {
    // an error occured
        alert(JSON.stringify(response.error));
    } else {
    // Done
        alert('Published to stream');
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM