He creado una demostración usando JavaScript para la API de búsqueda de fotos de Flickr. Ahora lo estoy convirtiendo a AngularJs. He buscado en internet y encontré la siguiente configuración.
Configuración:
myApp.config(function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
Servicio:
myApp.service('dataService', function($http) {
delete $http.defaults.headers.common['X-Requested-With'];
this.flickrPhotoSearch = function() {
return $http({
method: 'GET',
url: 'http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=3f807259749363aaa29c76012fa93945&tags=india&format=json&callback=?',
dataType: 'jsonp',
headers: {'Authorization': 'Token token=xxxxYYYYZzzz'}
});
}
});
Controlador:
myApp.controller('flickrController', function($scope, dataService) {
$scope.data = null;
dataService.flickrPhotoSearch().then(function(dataResponse) {
$scope.data = dataResponse;
console.log($scope.data);
});
});
Pero aún así recibí el mismo error. Aquí hay algunos enlaces que probé:
XMLHttpRequest no puede cargar la URL. Origen no permitido por Access-Control-Allow-Origin
fuente