I am developing an app in ionic
framework.
I have a function in controller that is supposed to download the facebook profile pictures which is as follows ($rootScope.user_friends
is the array of objects where in the fb_id property of object has the facebook id of the user whose profile picture is to be downloaded) :
$scope.downloadDP = function() {
// Make an API call for getting facebook profile picture URL
Session.userFBProfilePicture($rootScope.user_friends, function(response) {
console.log(response);
});
};
Following is the service/factory method :
// Makes API call for user's facebook DP URL
userFBProfilePicture: function(data_array, callback) {
var promises = [];
for (var i = 0; i < data_array.length; i++) {
var deffered = $q.defer();
var data = data_array[i];
$http({
method: 'GET',
url: 'https://graph.facebook.com/' + data.fb_id + '/picture?type=large&redirect=false',
}).
success(function(data) {
var url = data.url;
var targetPath = cordova.file.applicationStorageDirectory + "MyApp/" + data.mobile + ".png";
var trustHosts = true;
var options = {};
$cordovaFileTransfer.download(url, targetPath, options, trustHosts)
.then(function(result) {
deffered.resolve(result);
}, function(err) {
deffered.reject();
});
}).
error(function(error) {
deffered.reject();
});
promises.push(deffered);
}
return $q.all(promises);
},
The network call to the https://graph.facebook.com/' + data.fb_id + '/picture?type=large&redirect=false
url takes place successfully, and instead of server redirect, I get an object whose data.url
gives the actual location of user's profile picture.
I referred to this blog post : https://www.raymondcamden.com/2015/04/13/chaining-multiple-cordova-file-transfers-with-ngcordova/ and tried to promisify accordingly but in vain.
Also, I get nothing in my console.log(response);
in the controller method. I am not sure where I am going wrong, any help/pointers highly appreciated.