1

I have an AngularJS app in a VF page which will be interacting with the ChatterAPI. Obviously just making a request with Resource returns a 403 since I am not authenticated.

The only info I can find says that I need to create an app to connect, but I'm not sure if that still applies or will work if my app is on a VF page.

Visualforce

<apex:page showHeader="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">
  <html>
    <head>
      <script src="angular.js"></script>
      <script src="angular-resource.js"></script>
      <script src="app.js"></script>
    </head>
    <body ng-app="Community">
      <div ng-controller="CommunityCtrl"></div>
    </body>
    </html>
  </apex:page>

JS

angular.module('Community', ['ngResource']).controller('CommunityCtrl', function($scope, $resource) {
  $scope.community = $resource('/services/data/v35.0/connect/communities/COMMUNITY_ID/:action',
      {action:'chatter/feeds/news/me/feed-elements'},
      {get:{method:'JSONP'}}
    );
  $scope.community.get();
});
2
  • while using $resource you may need to set Authorization headers ?
    – Ratan Paul
    Jan 21, 2016 at 16:53
  • @Ratan so I set a constant that contains the API Session ID on the VF page, and now I am passing it in with headers: { "Authorization": "Token token='" + SESSION_ID + "'" } but still not having any luck
    – tekstrand
    Jan 21, 2016 at 18:38

1 Answer 1

0

Needed to set the bearer instead of the token.

JS

angular.module('Community', ['ngResource', 'config']).controller('CommunityCtrl', function($scope, $resource, SESSION_ID) {
  $scope.community = $resource('/new/services/data/v35.0/connect/communities/COMMUNITY_ID/chatter/feeds/news/me/feed-elements', {
        action:''
    }, {
        get: {
          method: 'GET',
          headers: {
            "Authorization": "Bearer " + SESSION_ID
          }
        },
      }
    );
  $scope.community.get();
});

Set Session ID from VF

angular.module('config', []).constant('SESSION_ID', '{!$Api.Session_ID}');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .