在 Facebook 上发布时出现 InsufficientPermissionException
InsufficientPermissionException while publishing on facebook
social 将我的网络应用程序与 Facebook 集成,现在当用户使用 Facebook 登录登录我的网络应用程序时,我能够从 his/her 个人资料中读取数据,但每当我尝试执行一些写操作,如 update status 或 publish a post on user's wall,我得到一个 InsufficientPermissionException
.
我的登录表单是:
<form name="fb_signin" id="fb_signin" action="${pageContext.request.contextPath}/auth/facebook">
<input type="hidden" name="scope" value="email,publish_stream,read_stream,user_status,user_photos,publish_actions,offline_access" />
<button class="btn btn-facebook" type="submit"> <i class="icon-facebook"></i>facebook</button>
</form>
此操作所需的配置部分是:
<bean id="userIdSource" class="org.springframework.social.security.AuthenticationNameUserIdSource"/>
<bean id="facebookApiHelper" class="org.springframework.social.facebook.config.support.FacebookApiHelper">
<constructor-arg index="0" ref="usersConnectionRepository"/>
<constructor-arg index="1" ref="userIdSource"/>
</bean>
<bean id="connectionFactoryLocator" class="org.springframework.social.security.SocialAuthenticationServiceRegistry">
<property name="authenticationServices">
<list>
<bean class="org.springframework.social.facebook.security.FacebookAuthenticationService">
<constructor-arg value="${facebook.app.id}" />
<constructor-arg value="${facebook.app.secret}" />
<!-- Important: The next property name changed from "scope" to "defaultScope" in 1.1.0.M4 -->
<property name="defaultScope" value="email,publish_actions,publish_stream,read_stream,user_status,user_photos,offline_access" />
</bean>
</list>
</property>
</bean>
现在我的控制器是:
public class FacebookOperationController {
private static final Logger logger = LoggerFactory.getLogger(FacebookOperationController.class);
@Autowired
protected FacebookApiHelper facebookApiHelper;
@Autowired
UserIdSource userIdSource;
private UsersConnectionRepository usersConnectionRepository;
@Autowired
public FacebookOperationController(UsersConnectionRepository usersConnectionRepository)
{
this.usersConnectionRepository = usersConnectionRepository;
}
@RequestMapping(method = RequestMethod.GET)
public String shareWithFacebook(WebRequest request,Model model){
Facebook facebook = facebookApiHelper.getApi();
Connection<Facebook> connection = usersConnectionRepository.createConnectionRepository(userIdSource.getUserId()).findPrimaryConnection(Facebook.class);
//connection.updateStatus("hello world");
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.set("link", "www.equinoxrar.com");
map.set("name", "Hi This is a Test Post");
map.set("caption", "Link Caption");
map.set("description", "Loooooo....ng description here");
map.set("message", "hello world");
// THE BELOW LINES ARE THE CRITICAL PART I WAS LOOKING AT!
map.set("picture", "http://www.imageRepo.com/resources/test.png"); // the image on the left
//map.set("actions", "{'name':'myAction', 'link':'http://www.bla.com/action'}"); // custom actions as JSON string
//String a = facebook.publish(userIdSource.getUserId(), "feed", map);
String b = connection.getApi().publish(userIdSource.getUserId(), "feed", map);
//publish(userIdToPostTo, "feed", map);
return "tilesname";
}
}
我能够从此控制器执行读取操作,但对任何写入操作都得到 InsufficientPermissionException
。任何人都可以知道吗?我得到的 Exception 是:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.social.InsufficientPermissionException: Insufficient permission for this operation.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
你能post更多的堆栈跟踪来进一步了解错误吗?
您也可以尝试创建一个 org.springframework.social.facebook.api.FacebookLink 对象并 post 使用
facebook.feedOperations().post链接("i'm posting", link);
实际上我已经解决了这个问题,当我使用应用程序管理员登录时,我可以从我的网络应用程序 post 在 facebook 中,但仅用于测试 facebook 应用程序 admin/developers/testers 添加到 facebook应用程序可以 post,对于所有其他我们必须将我的应用程序的详细信息(登录审查)提交给 facebook,一旦 facebook 批准相同,那么它将对所有用户开放。
social 将我的网络应用程序与 Facebook 集成,现在当用户使用 Facebook 登录登录我的网络应用程序时,我能够从 his/her 个人资料中读取数据,但每当我尝试执行一些写操作,如 update status 或 publish a post on user's wall,我得到一个 InsufficientPermissionException
.
我的登录表单是:
<form name="fb_signin" id="fb_signin" action="${pageContext.request.contextPath}/auth/facebook">
<input type="hidden" name="scope" value="email,publish_stream,read_stream,user_status,user_photos,publish_actions,offline_access" />
<button class="btn btn-facebook" type="submit"> <i class="icon-facebook"></i>facebook</button>
</form>
此操作所需的配置部分是:
<bean id="userIdSource" class="org.springframework.social.security.AuthenticationNameUserIdSource"/>
<bean id="facebookApiHelper" class="org.springframework.social.facebook.config.support.FacebookApiHelper">
<constructor-arg index="0" ref="usersConnectionRepository"/>
<constructor-arg index="1" ref="userIdSource"/>
</bean>
<bean id="connectionFactoryLocator" class="org.springframework.social.security.SocialAuthenticationServiceRegistry">
<property name="authenticationServices">
<list>
<bean class="org.springframework.social.facebook.security.FacebookAuthenticationService">
<constructor-arg value="${facebook.app.id}" />
<constructor-arg value="${facebook.app.secret}" />
<!-- Important: The next property name changed from "scope" to "defaultScope" in 1.1.0.M4 -->
<property name="defaultScope" value="email,publish_actions,publish_stream,read_stream,user_status,user_photos,offline_access" />
</bean>
</list>
</property>
</bean>
现在我的控制器是:
public class FacebookOperationController {
private static final Logger logger = LoggerFactory.getLogger(FacebookOperationController.class);
@Autowired
protected FacebookApiHelper facebookApiHelper;
@Autowired
UserIdSource userIdSource;
private UsersConnectionRepository usersConnectionRepository;
@Autowired
public FacebookOperationController(UsersConnectionRepository usersConnectionRepository)
{
this.usersConnectionRepository = usersConnectionRepository;
}
@RequestMapping(method = RequestMethod.GET)
public String shareWithFacebook(WebRequest request,Model model){
Facebook facebook = facebookApiHelper.getApi();
Connection<Facebook> connection = usersConnectionRepository.createConnectionRepository(userIdSource.getUserId()).findPrimaryConnection(Facebook.class);
//connection.updateStatus("hello world");
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.set("link", "www.equinoxrar.com");
map.set("name", "Hi This is a Test Post");
map.set("caption", "Link Caption");
map.set("description", "Loooooo....ng description here");
map.set("message", "hello world");
// THE BELOW LINES ARE THE CRITICAL PART I WAS LOOKING AT!
map.set("picture", "http://www.imageRepo.com/resources/test.png"); // the image on the left
//map.set("actions", "{'name':'myAction', 'link':'http://www.bla.com/action'}"); // custom actions as JSON string
//String a = facebook.publish(userIdSource.getUserId(), "feed", map);
String b = connection.getApi().publish(userIdSource.getUserId(), "feed", map);
//publish(userIdToPostTo, "feed", map);
return "tilesname";
}
}
我能够从此控制器执行读取操作,但对任何写入操作都得到 InsufficientPermissionException
。任何人都可以知道吗?我得到的 Exception 是:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.social.InsufficientPermissionException: Insufficient permission for this operation.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
你能post更多的堆栈跟踪来进一步了解错误吗?
您也可以尝试创建一个 org.springframework.social.facebook.api.FacebookLink 对象并 post 使用
facebook.feedOperations().post链接("i'm posting", link);
实际上我已经解决了这个问题,当我使用应用程序管理员登录时,我可以从我的网络应用程序 post 在 facebook 中,但仅用于测试 facebook 应用程序 admin/developers/testers 添加到 facebook应用程序可以 post,对于所有其他我们必须将我的应用程序的详细信息(登录审查)提交给 facebook,一旦 facebook 批准相同,那么它将对所有用户开放。