spring-attic / spring-social

Allows you to connect your applications with SaaS providers such as Facebook and Twitter.
http://projects.spring.io/spring-social
Apache License 2.0
619 stars 350 forks source link

Problem: An active access token must be used to query information about the current user #239

Open Aurusd opened 7 years ago

Aurusd commented 7 years ago

Try to post message on facebook. Use for start this link http://docs.spring.io/spring-social-facebook/docs/3.0.x/reference/htmlsingle/#posting-to-and-reading-feeds Use this code for simple test (before register myapp on developers.facebook, get valid token) String appId = "1507175062679391"; String appSecret = "281a84481098cab1500277915caa6c76"; OAuth2Operations oauth = new FacebookConnectionFactory(appId, appSecret).getOAuthOperations();

String appToken = oauth.authenticateClient().getAccessToken(); Facebook facebook = new FacebookTemplate(appToken); facebook.feedOperations().updateStatus("I'm trying out Spring Social!"); Have next stack trace (exception on the last line code)

14-Aug-2017 10:12:00.252 SEVERE [http-nio-8080-exec-2] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [mvc-dispatcher] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.social.ResourceNotFoundException: An active access token must be used to query information about the current user.] with root cause org.springframework.social.ResourceNotFoundException: An active access token must be used to query information about the current user.

Spring version: 4.3.7; social-core: 1.1.4.RELEASE; spring-social-facebook: 2.0.3.RELEASE Can someone explain what i missed?

AndriyBrez commented 7 years ago

Hi @Aurusd, First of all currently update status operation from the application is forbidden. You can read the only user public information like 'user name' ext. An error from Facebook means that you must specify userId instead of using default "me" userId which used in method updateStatus . For example:

@RunWith(SpringRunner.class)
@SpringBootTest
public class FacebookTests {
    @Value("${spring.social.facebook.appId}")
    private String appId;
    @Value("${spring.social.facebook.appSecret}")
    private String appSecret;
    @Test
    public void shouldFatchFacebookUserNameById() {
        OAuth2Operations oauth = new FacebookConnectionFactory(appId, appSecret).getOAuthOperations();
        String appToken = oauth.authenticateClient().getAccessToken();
        Facebook facebook = new FacebookTemplate(appToken);
        String markZuckerbergFacebookId = "4";
        User user = facebook.fetchObject(markZuckerbergFacebookId, User.class);
        assertEquals("Mark Zuckerberg", user.getName());
    }
}
Aurusd commented 7 years ago

almost month i am waiting for some answer))

Aurusd commented 7 years ago

Where i can get example code for post something on my facebook page with using spring-social? Or at least can you give some resource where i can find it?

Aurusd commented 7 years ago

How i can get user id facebook? via user authorization or another way? Maybe you provide some code for authorization via spring social?

AndriyBrez commented 7 years ago

Please look deeply in https://developers.facebook.com/docs/graph-api/ as I know spring social doesn't support new API v2.10