vstirbu/InstagramPlugin

Sharing screenshot image to Instagram

senthilmurugan-tag opened this issue · 4 comments

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.

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.

Can you explain how to do it?

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.

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);
                   });
}