简体   繁体   English

在node.js中将照片上传到Facebook的选项

[英]photo upload options to facebook in node.js

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 . 我正在使用nodejs和mongodb构建一个网站,并使用facebook进行身份验证。.我的用户将需要上传某些照片,而其他用户将可以查看它们

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. 由于我使用的是Facebook,所以我想知道是否应允许用户将其照片上传到其Facebook个人资料,并将链接保存到数据库中,以便以后其他用户可以查看。

Is this the right approach ? 这是正确的方法吗? or should I use flickr or picasa or something else ? 还是我应该使用flickr或picasa或其他?

I have to do this in javascript and I know facebook has support for this. 我必须使用javascript做到这一点,而且我知道Facebook支持此功能。

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 . 最后,我找到了模块connect-form,用于将文件上传到服务器,然后使用模块facebook-js将文件上传到facebook。 I found fb.api for "/me/feed" works perfectly in node.js server. 我发现用于“ / me / feed”的fb.api在node.js服务器中运行完美。 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. 但是,当我尝试对http://developers.facebook.com/docs/reference/api/album/中提到的“ / me / photos”使用图形API时,出现了错误。 That is because it expects the source to be in "multipart/form-data". 这是因为它期望源位于“ multipart / form-data”中。 In my html, it is already "multipart/form-data", otherwise I'll not get the file in the server side. 在我的html中,它已经是“ multipart / form-data”,否则我不会在服务器端获取文件。 In the server side, however, I am not very sure about how to embed this in FB.api... what should be the "source" parameter in FB.api "/me/ photos" ? 但是,在服务器端,我不太确定如何将其嵌入FB.api中。FB.api“ / me / photos”中的“ source”参数应该是什么? I tried this with "source:files.source" as mentioned in my example. 如示例中所述,我使用“ source:files.source”进行了尝试。 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: 您可以选择使用url将照片上传到Facebook,请阅读以下文章:
https://developers.facebook.com/blog/post/526/ https://developers.facebook.com/blog/post/526/

I suggest to use some CDN for photos like Amazon S3 which is very reliable and scalable. 我建议为CDS等照片使用一些CDN,它非常可靠且可扩展。 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) 然后,您也可以选择通过一个简单的API调用将其保存在Facebook上(在这种情况下,请不要忘记上传照片的扩展权限)

hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM