开发者

photo upload options to facebook in node.js

开发者 https://www.devze.com 2023-04-05 01:03 出处:网络
I am building a site with nodejs and mongodb and using facebook for authentication.. my users will be required to upload certain photo and others will be able to view them.

I am building a site with nodejs and mongodb and using facebook for authentication.. my users will be required to upload certain photo and others will be able to view them.

Since I am using facebook, I am wondering if I should allow users to upload their photos to their facebook profile and I'll save the links into the database so that later on other users can view this.

Is this the right approach ? or should I use flickr or picasa or something else ?

I have to do this in javascript and I know facebook has support for this.

Please let me know what you think.

EDIT:

Hi,

Finally I found the module connect-form to upload the file to the server and then uploading the file to facebook using the module facebook-js. I found fb.api for "/me/feed" works perfectly in node.js server. But when I tried to use the graph api for "/me/photos" as mentioned in http://developers.facebook.com/docs/reference/api/album/, I got the error. That is because it expects the source to be in "multipart/form-data". In my html, it is already "multipart/form-data", otherwise I'll not get the file in the server side. In the server side, however, I am not very sure about how to embed t开发者_高级运维his in FB.api... what should be the "source" parameter in FB.api "/me/ photos" ? I tried this with "source:files.source" as mentioned in my example. But it does not work. may be i am missing something very silly...

app.post('/', function(req, res, next){

  req.form.complete(function(err, fields, files){
    if (err) {
      next(err);
    } else {

      fb.apiCall('POST', '/me/photos',
        {access_token: fields.access_token, message: fields.message, source:files.source},
        function (error, response, body) {
            if (error) {
                console.log('Error in facebook Photo UPLOAD', error);
                return;
            }
          console.log('facebook RESPONSE :', response);
          console.log('facebook BODY :', body);
          res.redirect('back');
          //res.render('done', {body: body});
        }
      );

    }
  });


You have the option to upload photos to Facebook using the url, read the following article:
https://developers.facebook.com/blog/post/526/

I suggest to use some CDN for photos like Amazon S3 which is very reliable and scalable. Then you can optionally have it on Facebook too with a simple API call (don't forget about extended permissions to upload photos in this case)

hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消