aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api/FacebookPageManager.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-01-18 12:39:03 +0300
committerGravatar Vitaly Takmazov2018-01-18 12:39:03 +0300
commitfb5acff652f55a97b842c01de1b273c5da4a3f2f (patch)
treee045e56a3f822c0c2147f61f8d5d83774c7a1432 /juick-api/src/main/java/com/juick/api/FacebookPageManager.java
parentded1dbe08e7b8647624b8fb8cf9bc72462e40cf8 (diff)
drop spring-social-facebook
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/FacebookPageManager.java')
-rw-r--r--juick-api/src/main/java/com/juick/api/FacebookPageManager.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/juick-api/src/main/java/com/juick/api/FacebookPageManager.java b/juick-api/src/main/java/com/juick/api/FacebookPageManager.java
new file mode 100644
index 00000000..cb16dd0b
--- /dev/null
+++ b/juick-api/src/main/java/com/juick/api/FacebookPageManager.java
@@ -0,0 +1,34 @@
+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.http.converter.json.MappingJackson2HttpMessageConverter;
+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}")
+ private String pageId;
+ @Value("${facebook_page_access_token}")
+ 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();
+ api.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
+ ResponseEntity<String> response = api.exchange(uriComponents.toUri(),
+ HttpMethod.POST, null, String.class);
+ logger.info("Facebook response: {}", response.getBody());
+ }
+}