Search code examples
angularjsjsonpgoogle-plus

Unable to Display Google Plus Posts JSON on website


Im trying to get my Google Plus Page's posts, activity feed via JSON to display on my website.

Im using AngularJS to do that. Im not sure what im doing wrong.

When I run this, in the page it doesnt show anything. Also, I get CONSOLE error: Uncaught SyntaxError: Unexpected token : public:2

'use strict';
var app = angular.module('teamamr', ['teamamr.controller']);

var controllers = angular.module('teamamr.controller', []);

controllers.controller('googlePosts', function ($scope, $http) {
    $http.jsonp('https://www.googleapis.com/plus/v1/people/117069052843337874560/activities/public?maxResults=10&key=MYKEY')
        .then(function (data) {
            $scope.items = data;
            console.log(data);
        });
});

HTML PART: while html tag has ng-app="teamamr"

<div class="w-row" ng-controller="googlePosts">
        <div class="w-col w-col-4 services" ng-repeat="post in items">
          <h3>{{post.title}}</h3>
          <p><a href="{{post.url}}">read more</a></p>
        </div>
      </div>

Solution

  • Could you try to replace your JSONP call by this one

    $http.jsonp('https://www.googleapis.com/plus/v1/people/117069052843337874560/activities/public?callback=JSON_CALLBACK&maxResults=10&key=MYKEY').success(function(data, status, headers, config) {
      console.log(data);    
      $scope.items = data.items;
    });
    

    Please note that I have added a &callback=JSON_CALLBACK in the url and replace then(...) by success(...)