如何使用Ionic与Instagram分享照片

问题描述:

我正尝试将拍摄的照片分享给Instagram。我已经安装了social share plugin from ngCordova website如何使用Ionic与Instagram分享照片

但我无法让它工作。运行时,我没有错误。 我得到了成功的回应,但该图片未贴在Instagram墙上。

这里是从日志(xcode - >从实际设备运行到测试)的打印屏幕。 enter image description here

任何人都可以看到我在做什么错?

这里是我的控制器代码的一部分:我的HTML代码

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

    } 

}); 

部分:

<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 -->  
+0

可能是你缺少NG-科尔多瓦? –

+0

不,我把它添加到我的app.js文件中 – GY22

+0

请添加您遇到问题的错误。 –

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

而你需要添加此插件..(cordova插件添加https://github.com/vstirbu/InstagramPlugin.git) – imtiyaz

+0

我已经安装了该插件 – GY22

科尔多瓦deviceready事件中总结你的插件调用。它确保设备在调用插件之前完全加载。

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

您还可以使用$ionicPlatform.ready(function() {});

阅读更多信息:ngCordova common issues