[英]Facebook Graph Api Bad Request
I am making this request to the graph api and awlays getting a Bad Request
response from Facebook. 我向图形api发出此请求,awlays从Facebook得到了Bad Request
响应。 I changed it million times already, no luck. 我已经更改了一百万次了,没有运气。 Maybe I have read something wrong in the documentation... 也许我在文档中读错了...
var fd = new FormData();
fd.append("access_token", authToken);
fd.append("source", blob);
fd.append("message", message);
try {
$.ajax({
url: "https://graph.facebook.com/me/photos?access_token=" + authToken,
type: "POST",
data: fd,
processData: false,
contentType: false,
cache: false,
success: function (data) {
console.log("success " + data);
deferred.resolve(data);
},
error: function (shr, status, data) {
console.log("error " + data + " Status " + shr.status);
deferred.reject(data);
},
complete: function () {
console.log("Ajax Complete");
}
});
} catch (e) {
alert('error in ajax request ');
alert(JSON.stringify(e));
}
Here is the way to upload a base64 encoded photo directly to facebook using phonegap: 这是使用phonegap将base64编码的照片直接上传到Facebook的方法:
function postImage(fileURI, message) {
var deferred = $q.defer();
var win = function (r) {
deferred.resolve(r);
}
var fail = function (error) {
deferred.reject(error);
}
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = 'name_of_photo_' + Math.round((+(new Date()) + Math.random()));
options.mimeType = "image/jpg";
var params = new Object();
params.access_token = "your facebook access token ;)";
params.message = message;
params.no_story = false;
options.params = params;
var ft = new FileTransfer();
ft.upload(fileURI, "https://graph.facebook.com/v2.0/me/photos", win, fail, options);
return deferred.promise;
}
With the file-transfer plugin. 带有文件传输插件。 Add like this: cordova plugin add org.apache.cordova.file-transfer
像这样添加: cordova plugin add org.apache.cordova.file-transfer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.