How to share a photo with Instagram using Ionic

I'm trying to share the photo I took on Instagram. I installed the social download plugin from ngCordova website

But I can’t make it work. When I start, I get no errors. I get a successful response, but the image is not posted on the Instagram wall.

Here is the print screen from the logs (xcode → launched from the actual device for testing). enter image description here

Can anyone see what I'm doing wrong?

Here is part of my controller code:

app.controller('CameraCtrl', function($scope, $cordovaCamera, $cordovaSocialSharing, $rootScope, $state){

  $scope.takePicture = function(){
    var options = {
        quality: 75,
        destinationType: Camera.DestinationType.DATA_URI,
        sourceType: Camera.PictureSourceType.CAMERA,
        encodingType: Camera.EncodingType.JPEG,
        saveToPhotoAlbum: true,
        correctOrientation:true
    };
    $cordovaCamera.getPicture(options) 
      .then(function(imageURI){
          var imagePlaceholder = document.getElementById('placeholderPicture');
          imagePlaceholder.src = imageURI;
          $rootScope.imgShare = imageURI;
          //$scope.imgURI = "data:image/jpeg;base64," + imageURI;
          //$state.go('app.camera', {image: $scope.imgURI});
          //console.log('camera data: ' + angular.toJson(imageURI));
      },  function(error){
          console.log('error camera data: ' + angular.toJson(imageURI));
    });
  }

$scope.shareViaInstagram = function(message, image){
    socialType = "instagram";
    message = "test";
    image = $rootScope.imgShare;

     $cordovaSocialSharing.shareVia(socialType, message, image, null).then(function(result) {
      console.log('image shared to Instagram ', result);
      console.log('dddd', image);
      console.log('######', $rootScope.imgShare);
      //$state.go('app.finish');
}, function(err) {
      console.log('error in sharing to Instagram ', err);
});

  }

});

Part of my html code:

<div class="wrapperCamera">
        <div class="cameraContent padding">
            <img id="placeholderPicture" ng-src="{{imgShare}}">
            <br>
            <h2 class="customH2Camera">looking good!</h2>
            <br><br>
            <div class="socialIcons">
                <a href="" ng-click="shareViaInstagram(null, null, imgShare, null)"><img src="img/iconInstagram.svg" width="40"></a>
                &nbsp;&nbsp;&nbsp;
                <a href="" ng-click="shareViaFacebook(null, null, imgShare, null)"><img src="img/iconFacebook.svg" width="40"></a>
            </div>
        </div><!-- end cameraContent -->
    </div><!-- end WrapperCamera -->    
+4
source share
2 answers
  module.controller('ThisCtrl', function($scope, $cordovaInstagram) {
      // Get image from camera, base64 is good. See the
      // $cordovaCamera docs for more info
        $cordovaInstagram.share($scope.image.data, $scope.image.caption).then(function() {
        // Worked
      }, function(err) {
        // Didn't work
      });
    })
+1
source

deviceready . , .

document.addEventListener("deviceready", function () { 
  // your plugin call here 
});

$ionicPlatform.ready(function() {});

: ngCordova

+1

Source: https://habr.com/ru/post/1651534/


All Articles