foursqaure photo add against checkin

有些话、适合烂在心里 提交于 2020-01-17 07:10:13

问题


Me having strange problem while adding photo to foursquare checkin via node.js. When I use image files less than 10KB the photo got uploaded to that checkin but anything more than that in size just give me a BAD Gateway response from foursquare api server...

var http = require('http');
 var step = require('step');
 var request = require('request');

 exports.foursquarephoto = function(req, res){
        step(
                function(){

                     //var image_url = 'http://www.a2hosting.com/images/uploads/landing_images/node.js-hosting.png'; // size 9KB                     
                     var image_url = 'http://upload.wikimedia.org/wikipedia/commons/1/16/AsterNovi-belgii-flower-1mb.jpg'; // size 1MB


                    request.get({
                        url: image_url,
                        encoding: null
                    }, this);

                },
                function(err, response, body){

                    if(err) {

                    }

                    var imagename = new Date() + '.jpg';
                    var buffer = body;
                    var ImageBuffer = new Buffer(buffer, 'base64');

                    var r = request.post('https://api.foursquare.com/v2/photos/add' , this);
                    var form = r.form();
                    // foursquare post
                    // https://foursquare.com/winz_dean/checkin/52241e7b11d2264c2b178d90

                    form.append('checkinId', '52241e7b11d2264c2b178d90');                   
                    form.append('photo', ImageBuffer, { filename: imagename });                 
                    form.append('oauth_token', 'FGDS4XZF0U0DUQKZG1TCYFWIEUPZXCQG3SLMCUQHAESN2JLO');

                },
                function(err, response, body){

                    if(err) {
                        res.send(err);
                    }

                    res.send(200, body);
                }
        ); 
     };

来源:https://stackoverflow.com/questions/18586466/foursqaure-photo-add-against-checkin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!