node.js - Picasa npm module not working -


i had been using picasa npm module google photos account.

    const options={     maxresults : 10     }     picasa.getphotos(accesstoken, options, (error, photos)) 

it returning photos. recently, showing following error

{      "error":{     "stack":"typeerror: cannot read property 'map' of undefined\n     @ executerequest (/home/toobler/gosite- dashboard/node_modules/picasa/src/picasa.js:162:35)\n     @ request.request.(anonymous function).error [as _callback]  (/home/toobler/gosite- dashboard/node_modules/picasa/src/executerequest.js:22:7)\n    @  request.self.callback (/home/toobler/gosite- dashboard/node_modules/request/request.js:188:22)\n    @ emittwo  (events.js:106:13)\n    @ request.emit (events.js:191:7)\n    @  request.<anonymous> (/home/toobler/gosite- dashboard/node_modules/request/request.js:1171:10)\n    @ emitone  (events.js:96:13)\n    @ request.emit (events.js:188:7)\n    @  incomingmessage.<anonymous> (/home/toobler/gosite- dashboard/node_modules/request/request.js:1091:12)\n    @  incomingmessage.g (events.js:292:16)\n    @ emitnone  (events.js:91:20)\n    @ incomingmessage.emit (events.js:185:7)\n     @ endreadablent (_stream_readable.js:974:12)\n    @  _combinedtickcallback (internal/process/next_tick.js:80:11)\n    @  process._tickdomaincallback (internal/process/next_tick.js:128:9)",  "message":"cannot read property 'map' of undefined"    } } 

if use

picasa.getalbums(accesstoken, options, (error, photos)) 

it returning albums.

also if specify albumid in options,

const options={     maxresults : 10,     albumid : "<albumid>"  } picasa.getphotos(accesstoken, options, (error, photos)) 

is returning photos in particular album. however, want photos irrespective of albums. missing?

following code /home/toobler/gosite- dashboard/node_modules/picasa/src/picasa.js

    'use strict'      const querystring = require('querystring')      const executerequest = require('./executerequest')      const google_auth_endpoint = 'https://accounts.google.com/o/oauth2/auth'     const google_api_host = 'https://www.googleapis.com'     const google_api_path = '/oauth2/v3/token'     const google_api_path_new = '/oauth2/v4/token'      const picasa_scope = 'https://picasaweb.google.com/data'     const picasa_api_feed_path = '/feed/api/user/default'     const picasa_api_entry_path = '/entry/api/user/default'      const fetch_as_json = 'json'      function picasa () {     this.executerequest = executerequest     }      picasa.prototype.getphotos = getphotos     picasa.prototype.postphoto = postphoto     picasa.prototype.deletephoto = deletephoto     picasa.prototype.getalbums = getalbums     picasa.prototype.createalbum = createalbum      // auth utilities     picasa.prototype.getauthurl = getauthurl     picasa.prototype.getaccesstoken = getaccesstoken     picasa.prototype.renewaccesstoken = renewaccesstoken      function getalbums (accesstoken, options, callback) {     const accesstokenparams = {         alt          : fetch_as_json,         access_token : accesstoken     }      options = options || {}      const requestquery = querystring.stringify(accesstokenparams)      const requestoptions = {         url : `${picasa_scope}${picasa_api_feed_path}?${requestquery}`,         headers: {         'gdata-version': '2'         }     }      this.executerequest('get', requestoptions, (error, body) => {         if (error) return callback(error)          const albums = body.feed.entry.map(         entry => parseentry(entry, albumschema)         )          callback(null, albums)     })     }      function deletephoto (accesstoken, albumid, photoid, callback) {     const requestquery = querystring.stringify({         alt          : fetch_as_json,         access_token : accesstoken     })      const requestoptions = {         url : `${picasa_scope}${picasa_api_entry_path}/albumid/${albumid}/photoid/${photoid}?${requestquery}`,         headers: {         'if-match': '*'         }     }      this.executerequest('del', requestoptions, callback)     }      function createalbum (accesstoken, albumdata, callback) {     const requestquery = querystring.stringify({         alt          : fetch_as_json,         access_token : accesstoken     })      const albuminfoatom = `<entry xmlns='http://www.w3.org/2005/atom'                                 xmlns:media='http://search.yahoo.com/mrss/'                                 xmlns:gphoto='http://schemas.google.com/photos/2007'>                             <title type='text'>${albumdata.title}</title>                             <summary type='text'>${albumdata.summary}</summary>                             <gphoto:access>private</gphoto:access>                             <category scheme='http://schemas.google.com/g/2005#kind'                                 term='http://schemas.google.com/photos/2007#album'></category>                             </entry>`      const requestoptions = {         url       : `${picasa_scope}${picasa_api_feed_path}?${requestquery}`,         body      : albuminfoatom,         headers   : {'content-type': 'application/atom+xml'}     }      this.executerequest('post', requestoptions, (error, body) => {         if (error) return callback(error)          const album = parseentry(body.entry, albumschema)          callback(error, album)     })     }      function postphoto (accesstoken, albumid, photodata, callback) {     const requestquery = querystring.stringify({         alt          : fetch_as_json,         access_token : accesstoken     })      const photoinfoatom = `<entry xmlns="http://www.w3.org/2005/atom">                             <title>${photodata.title}</title>                             <summary>${photodata.summary}</summary>                             <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/photos/2007#photo"/>                             </entry>`      const requestoptions = {         url       : `${picasa_scope}${picasa_api_feed_path}/albumid/${albumid}?${requestquery}`,         multipart : [         {'content-type' : 'application/atom+xml', body : photoinfoatom},         {'content-type' : photodata.contenttype, body : photodata.binary}         ]     }      this.executerequest('post', requestoptions, (error, body) => {         if (error) return callback(error)          const photo = parseentry(body.entry, photoschema)          callback(error, photo)     })     }      function getphotos (accesstoken, options, callback) {     const accesstokenparams = {         alt          : fetch_as_json,         kind         : 'photo',         access_token : accesstoken     }      options = options || {}      if (options.maxresults) accesstokenparams['max-results'] = options.maxresults      const albumpart = options.albumid ? `/albumid/${options.albumid}` : ''      const requestquery = querystring.stringify(accesstokenparams)      const requestoptions = {         url : `${picasa_scope}${picasa_api_feed_path}${albumpart}?${requestquery}`,         headers: {         'gdata-version': '2'         }     }      this.executerequest('get', requestoptions, (error, body) => {         if (error) return callback(error)          const photos = body.feed.entry.map(         entry => parseentry(entry, photoschema)         )          callback(null, photos)     })     }      const albumschema = {     'gphoto$id'                : 'id',     'gphoto$name'              : 'name',     'gphoto$numphotos'         : 'num_photos',     'published'                : 'published',     'title'                    : 'title',     'summary'                  : 'summary',     'gphoto$location'          : 'location',     'gphoto$nickname'          : 'nickname'     }      const photoschema = {     'gphoto$id'                : 'id',     'gphoto$albumid'           : 'album_id',     'gphoto$access'            : 'access',     'gphoto$width'             : 'width',     'gphoto$height'            : 'height',     'gphoto$size'              : 'size' ,     'gphoto$checksum'          : 'checksum',     'gphoto$timestamp'         : 'timestamp',     'gphoto$imageversion'      : 'image_version',     'gphoto$commentingenabled' : 'commenting_enabled',     'gphoto$commentcount'      : 'comment_count',     'content'                  : 'content',     'title'                    : 'title',     'summary'                  : 'summary'     }      function parseentry (entry, schema) {     let photo = {}      object.keys(schema).foreach(schemakey => {         const key = schema[schemakey]          if (key) {         const value = checkparam(entry[schemakey]);          photo[key] = value;         }     })      return photo     }      function getauthurl (config) {     const authenticationparams = {         access_type   : 'offline',         scope         : `${picasa_scope}`,         response_type : 'code',         client_id     : config.clientid,         redirect_uri  : config.redirecturi     }      const authenticationquery = querystring.stringify(authenticationparams)      return `${google_auth_endpoint}?${authenticationquery}`     }      function getaccesstoken (config, code, callback) {     const accesstokenparams = {         grant_type    : 'authorization_code',         code          : code,         redirect_uri  : config.redirecturi,         client_id     : config.clientid,         client_secret : config.clientsecret     }      const requestquery = querystring.stringify(accesstokenparams)     const options = {         url : `${google_api_host}${google_api_path}?${requestquery}`     }      this.executerequest('post', options, (error, body) => {         if (error) return callback(error)          callback(null, body.access_token, body.refresh_token)     })     }      function renewaccesstoken (config, refresh_token, callback){     const refreshtokenparams = {         grant_type: 'refresh_token',         client_id: config.clientid,         client_secret: config.clientsecret,         refresh_token: refresh_token     }      const requestquery = querystring.stringify(refreshtokenparams)     const options = {         url: `${google_api_host}${google_api_path_new}?${requestquery}`     }      this.executerequest('post', options, (error, body) => {         if (error) return callback(error)          callback(null, body.access_token)     })     }      function checkparam (param) {     if (param === undefined) return ''     else if (isvalidtype(param)) return param     else if (isvalidtype(param['$t'])) return param['$t']     else return param     }      function isvalidtype (value) {     return typeof value === 'string' || typeof value === 'number'     }      module.exports = picasa 


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -