vstirbu / InstagramPlugin

Instagram plugin for PhoneGap/Cordova
MIT License
120 stars 78 forks source link

Sharing screenshot image to Instagram #29

Closed senthilmurugan-tag closed 9 years ago

senthilmurugan-tag commented 10 years ago

Our functionality is take the screenshot of current screen and share this image to Instagram.

We are using this https://github.com/gitawego/cordova-screenshot for taking screenshot. It will return the screenshot image path only in android. We want to use your plugin for android only. How can we share this taken screenshot image to Instagram in android.

What is the value we should use for canvasIdOrDataUrl and caption.

vstirbu commented 10 years ago

The general approach for sharing the image when having the file path is to get the file content using the FileSystem API. The key API for getting the content in a form that is compatible with the plugin is FileReader.readAsDataURL.

senthilmurugan-tag commented 10 years ago

Can you explain how to do it?

vstirbu commented 10 years ago

There is a good article on HTML5Rocks on how to use the Filesystem API. Have a look at the Reading a file by name section.

manuelpaulo commented 9 years ago

Here's how to do it: Add org.apache.cordova.file and use this code:


navigator.screenshot.save(function(error,res){
                                         if(error){
                                         console.error(error);
                                         }else{
                                        window.resolveLocalFileSystemURL("file://"+res.filePath, gotFile, fail);
});

function fail(e) {
    console.log("FileSystem Error");
    console.dir(e);
}

function gotFile(fileEntry) {
    fileEntry.file(function(file) {
                   var reader = new FileReader();
                   reader.onloadend = function(e) {
                   Instagram.share(this.result, function (err) {
                                   if (err) {
                                   console.log("not shared insta");
                                   } else {
                                   console.log("shared insta");
                                   }
                                   });
                   }
                   reader.readAsDataURL(file);
                   });
}