diff options
author | 2018-02-06 17:54:49 +0300 | |
---|---|---|
committer | 2018-02-08 14:29:08 +0300 | |
commit | 7ed3795da542bab397ee7ed8978bde896abf5cf4 (patch) | |
tree | 0531bf226f31b7d4f428248b1f176f5ecbab0874 /juick-server/src/main/java/com/juick/api/FacebookPageManager.java | |
parent | 089f00eaf912781cebd4dc87e9c445051d0cc532 (diff) |
server: merge api and ws
Diffstat (limited to 'juick-server/src/main/java/com/juick/api/FacebookPageManager.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/api/FacebookPageManager.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/api/FacebookPageManager.java b/juick-server/src/main/java/com/juick/api/FacebookPageManager.java new file mode 100644 index 00000000..e9ed0e59 --- /dev/null +++ b/juick-server/src/main/java/com/juick/api/FacebookPageManager.java @@ -0,0 +1,32 @@ +package com.juick.api; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponents; +import org.springframework.web.util.UriComponentsBuilder; + +@Component +public class FacebookPageManager { + private static Logger logger = LoggerFactory.getLogger(FacebookPageManager.class); + @Value("${facebook_page_id:12345678}") + private String pageId; + @Value("${fb_page_access_token:12345678}") + private String accessToken; + + public void post(String status, String link) { + UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://graph.facebook.com/{page_id}/feed") + .queryParam("message", status) + .queryParam("link", link) + .queryParam("access_token", accessToken) + .buildAndExpand(pageId); + RestTemplate api = new RestTemplate(); + ResponseEntity<String> response = api.exchange(uriComponents.toUri(), + HttpMethod.POST, null, String.class); + logger.info("Facebook response: {}", response.getBody()); + } +} |