简体   繁体   English

通过春季社交InsufficientPermissionException发布到Facebook墙

[英]Post to facebook wall through spring social InsufficientPermissionException

I am trying to make a very simple app with spring social, the app is not for public. 我正在尝试使用Spring Social创建一个非常简单的应用程序,该应用程序不面向公众。 What I am trying to achieve is to post to my wall or to the page that I administer. 我要实现的目标是张贴到我的墙上或我管理的页面上。

Trying to ask facebook for access to manage_pages permission they denied because as they said "You do not need to request these permissions because your blog or CMS is integrated with an app that you admin. As an App admin, you can already access these permissions and post to your timeline or a page you admin. You can provide access to additional users by adding them as developers of your App." 尝试要求Facebook访问manage_pages权限时,他们拒绝了,因为他们说:“您不需要请求这些权限,因为您的博客或CMS已与您管理的应用程序集成在一起。作为应用程序管理员,您已经可以访问这些权限,并且发布到您的时间轴或您管理的页面。您可以通过将其他用户添加为您的应用程序开发人员来提供访问权限。”

Now in the code. 现在在代码中。 I altered a bit spring social showcase example. 我更改了一些春季社交展示示例。 And my case is as follows: 1) I login to facebook through my app 2) Trying to get the number of pages that I administer 3) Post to my wall. 我的情况如下:1)我通过我的应用程序登录到Facebook 2)试图获取我管理的页面数3)发布到我的墙上。

For step two I am using this code: 对于第二步,我使用以下代码:

if (facebook.pageOperations().getAccounts() != null) {
        System.out.println("SIZE OF ACCCOUNTS IS: " + facebook.pageOperations().getAccounts().size());
    }

The size of accounts is always 0. So this means that although I should be able to post to the pages that I am administrator I can not even see them. 帐户的大小始终为0。因此,这意味着尽管我应该能够发布到我是管理员的页面,但什至看不到它们。 Am I correct? 我对么?

For step three now: 现在进行第三步:

facebook.feedOperations().updateStatus("I'm trying out Spring Social!");
    facebook.feedOperations().post(new PostData("me").message("I'm trying out Spring Social!")
        .link("http://www.springsource.org/spring-social", null, "Spring Social", "The Spring Social Project", "Spring Social is an extension to Spring to enable applications to connect with service providers."));
    System.out.println("FEED POSTED");

both of those attempts fail with the following exception: 这些尝试均失败,但以下异常除外:

org.springframework.social.InsufficientPermissionException: Insufficient permission for this operation. org.springframework.social.InsufficientPermissionException:此操作的权限不足。

Could someone help please? 有人可以帮忙吗?

It seems like you have not asked/granted the permissions that you need during login. 似乎您没有在登录时询问/授予所需的权限。 The first thing that you need to do is implement login and ensure sure that you include the correct scope ie permission ( manage_pages ) during login. 您需要做的第一件事是实现登录,并确保您在登录期间包括正确的范围,即权限( manage_pages )。 Since your requirements also include publishing, include these permissions publish_pages and/or publish_actions depending on whether you want to publish as a page or yourself. 由于您的要求还包括发布, publish_actions根据您要发布为页面还是自己来包含这些权限publish_pages和/或publish_actions eg if you are using the JS SDK , it would look something like this: 例如,如果您使用的是JS SDK ,则它将类似于以下内容:

 FB.login(function(response) {
   // handle the response
 }, {scope: 'manage_pages, publish_pages, publish_actions'});

Once you do this, on logging in, you will be prompted if you want to grant these permissions. 完成此操作后,登录时将提示您是否要授予这些权限。 On granting, your access token will contain these permissions and you will be able to make a call to /me/accounts which will give you a list of pages that you admin and their respective access tokens. 授予权限后,您的访问令牌将包含这些权限,并且您可以调用/me/accounts ,这将为您提供您管理的页面列表及其各自的访问令牌。 It will look something like this: 它看起来像这样:

"data": [
    {
      "access_token": "CAACEdEose0cBAAy...",
      "category": "Food/Grocery",
      "name": "Page Name",
      "id": "1234567890",
      "perms": [
        "ADMINISTER",
        "EDIT_PROFILE",
        "BASIC_ADMIN"
      ]
    },
    ...
    ]

If you want to publish as yourself, then you can continue using the current user access token. 如果您想以自己的身份发布,则可以继续使用当前的用户访问令牌。 Else if you want to publish as a page, grab the page access token from the response above and use that to make the POST request against the page id. 否则,如果要发布为页面,请从上面的响应中获取页面访问令牌,然后使用该令牌对页面ID发出POST请求。

And if you are creating an app for yourself and not for the public, then you do not need to submit these permissions for review provided you are an admin or have some role in the app. 而且,如果您是为自己而非公众创建应用程序,则只要您是该应用程序的管理员或角色,就无需提交这些权限进行审查。

You might be able to find some more context here . 您也许可以在这里找到更多上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM