Created
August 11, 2016 08:16
-
-
Save dominicgan/1a55ebf2b2d2249e70527ea7c579303d to your computer and use it in GitHub Desktop.
Publish photo to Facebook (jQuery Ajax - POST) - August 2016
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
var pgToke = 'YOUR_PAGE_TOKEN_HERE'; // generate page token with GET or in Facebook graph explorer | |
var caption = document.getElementById('post_status').value; | |
var fileUl = document.getElementById('post_img'); | |
file = fileUl.files[0]; | |
// Create the FormData object and attach to a key name "file" | |
var fd = new FormData(); | |
fd.append("file", file); | |
fd.append("caption", caption); | |
// ajax method to POST photo to Facebook page | |
$.ajax({ | |
type: "POST", | |
url: "https://graph.facebook.com/v2.7/YOUR_PAGE_ID_HERE/photos?access_token="+pgToke, | |
data: fd, | |
contentType: false, | |
processData: false, | |
success: function(dat, status, xhr){ | |
console.log(xhr.responseText); | |
}, | |
error: function(xhr, str, err){ | |
console.log(xhr.responseText); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment