Created
January 24, 2014 16:46
-
-
Save AlfredoCasado/8601134 to your computer and use it in GitHub Desktop.
Publish a photo in a facebook fan page. Using groovy and RestFB API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grapes( | |
@Grab(group='com.restfb', module='restfb', version='1.6.12') | |
) | |
import com.restfb.DefaultFacebookClient | |
import com.restfb.json.JsonObject | |
import com.restfb.types.FacebookType | |
import com.restfb.Parameter | |
import com.restfb.BinaryAttachment | |
import java.io.FileInputStream | |
def token = "YOUR_TOKEN" | |
def page = "PAGE_ID" | |
def facebook = new DefaultFacebookClient(token) | |
// two ways of publishing photos in a facebook fan page | |
// publish a photo in the page album. | |
facebook.publish("${page}/photos", | |
String.class, | |
BinaryAttachment.with("testImage.jpg",new FileInputStream("<URL_TO_IMAGE_IN_YOUR_FILESYSTEM>")), | |
Parameter.with("message", "A example test message that appears next to the image")) | |
// this publish a post in the page feed with a photo url. | |
facebook.publish("${page}/feed", | |
String.class, | |
Parameter.with("message", "A example test message that appears next to the image"), | |
Parameter.with("picture", "https://www.google.es/images/srpr/logo11w.png"), | |
Parameter.with("caption", "google logo")) | |
// when you make a GET to PAGE_ID/feed the photos appears as well. Facebook return the photos with "type:photo" and the messages you POST to "feed" with "type:link". Extrange behaviour posting photos to 'photos' that can be retrieved in 'feed' as well... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment