在javascript facebook api上发布图像事件
好吧,我被卡住了,我想在facebook上创建一个事件,使用javascript facebook api,我想在事件封面上加载一个图像。我想不出我该怎么做 我在画布上创建了一个图像,我可以使用sendasbinary函数上传到facebook 发件人: 这个函数呢在javascript facebook api上发布图像事件,javascript,facebook,facebook-graph-api,Javascript,Facebook,Facebook Graph Api,好吧,我被卡住了,我想在facebook上创建一个事件,使用javascript facebook api,我想在事件封面上加载一个图像。我想不出我该怎么做 我在画布上创建了一个图像,我可以使用sendasbinary函数上传到facebook 发件人: 这个函数呢 Facebook.prototype.postImageToFacebook = function(authToken, filename, mimeType, imageData, message){ try {
Facebook.prototype.postImageToFacebook = function(authToken, filename, mimeType, imageData, message){
try {
showMessage("Creating post...");
// this is the multipart/form-data boundary we'll use
var boundary = '----------RaNdOm_crAPP' + getBoundary();
// let's encode our image file, which is contained in the var
var formData = '--' + boundary + '\r\n';
formData += 'Content-Disposition: form-data; name="source"; filename="' + filename + '"\r\n';
formData += 'Content-Type: ' + mimeType + '\r\n\r\n';
for (var i = 0; i < imageData.length; ++i)
{
formData += String.fromCharCode(imageData[ i ] & 0xff);
}
formData += '\r\n';
formData += '--' + boundary + '\r\n';
formData += 'Content-Disposition: form-data; name="message"\r\n\r\n';
formData += message + '\r\n';
formData += '--' + boundary + '--\r\n';
//var xhr = new XMLHttpRequest();
var xhr = null;
if (window.XDomainRequest) {
xhr = new XDomainRequest();
}
else if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.onload = function() {
window.alert("The photo was published successfully!!");
};
showMessage("Sending request...");
xhr.open("POST", "https://graph.facebook.com/me/photos?access_token=" + authToken, true);
if (xhr.setRequestHeader)
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
xhr.sendAsBinary(formData);
} catch (ex) {
stopWaitingSpin();
debugLog(ex);
}
};
我可以创建一个事件
但需要打什么电话才能将图像发送到活动封面
感谢所有人,实际上文档中还没有提到它,但是要发布某个活动的封面照片,您需要使用param调用
\POST/{event id}
:
{event id}
可以在创建事件时获得
FB.api("/{event-id}", "POST", {
cover_url: {image-url}
},
function(response) {
console.log(response); // you'll get the response as 'true' or 'false'
});
我放弃了,离开了这个项目几个月。当我有空的时候,我会试试你告诉我的。非常感谢你!
FB.api("/{event-id}", "POST", {
cover_url: {image-url}
},
function(response) {
console.log(response); // you'll get the response as 'true' or 'false'
});