本文介绍了如何通过手机上传在Facebook活动上的照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Phonegap。
I am working on Phonegap .
现在我正在使用: -
Right now I am using this :-
$.post("https://graph.facebook.com/"+Event_Id, {
"Photos":uri,
"access_token": fbAccessToken
},
function(data){
Some code here
}, "json");
推荐答案
我知道无法上传单张照片。在不眠之夜和研究的日子,我终于得到它与cordova文件传输插件工作
I know the pain of not being able to upload a single photo. After sleepless nights and days of research, I finally got it to work with the cordova file-transfer plugin
首先添加插件: cordova插件添加org.apache.cordova.file-transfer
然后,使用这个代码(注意,我使用angular.js。承诺或使用像rsvp或Q这样的库来做你的承诺):
Then, use this code (Note that I am using angular.js. Either do not user promises or use a library like rsvp or Q to make your promises):
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;
}
这篇关于如何通过手机上传在Facebook活动上的照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!