0

I am trying to connect to tumblr API with angularJS

EDIT

I now I try to do:

JS:

tumblr.controller('tumblrs', function($scope, $http) {
    $http.get("http://www.tinymediaempire.tumblr.com/api/read/json/")
        .success(function(responses) {$scope.post = responses.response.posts;});
    });

HTML:

<div ng-controller="tumblrs">       
    <ol>
        <li ng-repeat="spost in post">{{ spost.photos[0].alt_sizes[0].url }}</li>
    </ol>
</div>
Adam Azad
  • 11,171
  • 5
  • 29
  • 70

1 Answers1

0

In your JSON example I don't see a .photo_url_500 property in the photos objects.

I think you need to refer to .alt_sizes[1].url to get the url for a 500px image.

You also need to use ng-src attribute instead of src as the img tag will try and load from the literal text before angular has loaded:

<img ng-src="{{ photo.alt_sizes[1].url }}" />
Starscream1984
  • 3,072
  • 1
  • 19
  • 27
  • If you just put `{{ photo.alt_sizes[1].url }}` above the `img` tag, does it display a url as text? – Starscream1984 Nov 26 '15 at 17:28
  • it print {{ photo.alt_sizes[1].url }} – Daniel Romano Nov 26 '15 at 17:42
  • Sounds like your angular isn't working at all if it isn't parsing the bracket notation. post your module code as well as the controller, and post where you put your `ng-app` directive – Starscream1984 Nov 27 '15 at 08:56
  • `var tumblr = angular.module('tumblr', []);` `` – Daniel Romano Nov 27 '15 at 09:41
  • That looks ok, I don't understand why it wouldn't parse the bracket notation. Definitely no errors in Chrome dev tools console? – Starscream1984 Nov 27 '15 at 11:52
  • this is the erorr `XMLHttpRequest cannot load http://api.tumblr.com/v2/blog/NAME/posts/photo?api_key=KEY&notes_info=true. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.` – Daniel Romano Nov 27 '15 at 14:58
  • That's a CORS error - take a look at the question and answers on this post to see how to go about making a `jsonp` request instead: http://stackoverflow.com/questions/19367933/allow-my-tumblr-blogs-content-to-be-accessed-by-another-page – Starscream1984 Nov 30 '15 at 15:37