2016-08-17 60 views
4

我正嘗試將拍攝的照片分享給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

請添加您遇到問題的錯誤。 –

回答

1
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

1

科爾多瓦deviceready事件中總結你的插件調用。它確保設備在調用插件之前完全加載。

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

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

閱讀更多信息:ngCordova common issues

相關問題