1

I've been trying to post some data from my webpage directly to a facebook group wall. Is is possible to achieve? Here's a code i used:

$.getScript('//connect.facebook.net/en_UK/all.js', function(){
FB.init({
      appId      : myAppId,
      xfbml      : true,
      version    : 'v2.0'
    });
FB.api('/groupId/feed', 'post', { link: 'linkToMyPage', name: 'Name' } , function(response) {
          if (!response || response.error) {
            alert('Error occured');
          } else {
            alert('Success!');
          }
        });

Any help will be appreciated!

Gryphz
  • 33
  • 3
  • possible duplicate of [oAuth exception #200 while trying to post to groups after recent Facebook maintenance](http://stackoverflow.com/questions/19535885/oauth-exception-200-while-trying-to-post-to-groups-after-recent-facebook-mainte) – Blake G Jun 30 '14 at 00:12

1 Answers1

0

By comparing your code against Facebook's sample code, I noticed that you need to capitialize "POST", also their code nests { link: 'linkToMyPage', name: 'Name' }' within an Object block. So I am thinking you should replace the link and name with something similar to:

"object": {
            "link": linkToMyPage,
            "name": 'Name'
        } 

Here is the API doc, which describes how to publish to a Group feed.

Blake G
  • 581
  • 7
  • 24
  • Just tried this: FB.api("/id/feed", "POST", { "object": { "message": "This is a test message", "link": "link", "name": "Random name" } }, but it doesn't seem to work. – Gryphz Jun 29 '14 at 21:17
  • "name" is not a valid field. You need to remove it. You can only post a message with a link. The username is inherent within your current access token. (I assume you've performed a login before executing this code). Remove the 'Name' entry in your object, and let me know if it works. – Blake G Jun 29 '14 at 21:26
  • Oh, i see. I tried this: FB.login(function(){ FB.api('/groupId/feed', 'post', {message: 'mymessage', link: 'mylink'}); }, {scope: 'publish_actions'});. It works if i use /me/feed, but as soon as im changing it to /groupID/feed it does nothing. – Gryphz Jun 29 '14 at 21:46
  • Can you paste the Response here? (Instead of triggering an alert, print the response) – Blake G Jun 29 '14 at 21:59
  • code: 200 message: "(#200) Insufficient permission to post to target on behalf of the viewer" type: "OAuthException". Do i need some kind of a access token? – Gryphz Jun 29 '14 at 22:08
  • Have you logged in as a user? – Blake G Jun 29 '14 at 22:39
  • Yes i did. I'm probably missing something really obvious, i'm new to this, sorry. – Gryphz Jun 29 '14 at 22:42
  • Take a look (here)[https://developers.facebook.com/docs/facebook-login/permissions/v2.0]. I believe you lack sufficient permissions to write to a group wall. What happens when you GET the permissions via: `GET /{user-id}/permissions` – Blake G Jun 29 '14 at 22:44
  • I've got permissions granted for :"installed", "public_profile", "publish_actions", "user_groups". – Gryphz Jun 29 '14 at 23:00
  • Got this idea from here: http://stackoverflow.com/questions/19535885/oauth-exception-200-while-trying-to-post-to-groups-after-recent-facebook-mainte Remove the app from your installed apps in your facebook privacy settings. Login to your app again, but this time as it requests publish permissions, you need to allow publish-rights to Public, not just My Friends, or Only Me. Does doing that change things? – Blake G Jun 29 '14 at 23:24