javascript - Retrieving Facebook Profile Picture URL -


i using satellizer authentication in mean app. after auth complete want profile picture of user. following code.

angular controller

(function(){     'use strict';     angular         .module('nayakans07')         .controller('registercontroller', registercontroller);      function registercontroller ($scope, $auth) {          $scope.authenticate = function (provider) {             $auth.authenticate(provider)                 .then(function (res) {                     console.log(res);                 }, autherrorhandler);         };          function autherrorhandler (err) {             console.log(err);         }     }  })(); 

node.js route handler

(function () {     'use strict';      var request = require('request');     var qs = require('querystring');     var tokenhelper = require('../helpers/tokenhelper.js');     var config = require('../config/configuration.js');     var member = require('../models/membermodel.js');      module.exports = function (req, res) {         var accesstokenurl = 'https://graph.facebook.com/oauth/access_token';         var grapapiprofileurl = 'https://graph.facebook.com/me';         var graphapiprofileimageurl = 'https://graph.facebook.com/me/picture?width=250&json=true';          var params = {             client_id: req.body.clientid,             redirect_uri: req.body.redirecturi,             code: req.body.code,             client_secret: config.facebook_secret         };          request.get({             url: accesstokenurl,             qs: params         }, function (err, response, accesstoken) {             accesstoken = qs.parse(accesstoken);             request.get({                 url: grapapiprofileurl,                 qs: accesstoken,                 json: true             }, function (err, response, profile) {                 console.log(profile);                 member.findone({                     facebookid: profile.id                 }, function (err, existingmember) {                     if (existingmember) {                         return res.status(200).send({                             user: existingmember,                             token: tokenhelper.createtoken(existingmember, req, res)                         });                     } else {                         request.get({                             url: graphapiprofileimageurl,                             qs: accesstoken,                         }, function (err, response, profileimage) {                             console.log(profileimage);                             var fbdata = {                                 facebookid: profile.id,                                 fullname: profile.name,                                 email: profile.email,                                 profileimage: profileimage                             };                             return res.status(200).send(fbdata);                         });                     }                 });             });         });     };   })(); 

after access token facebook call https://graph.facebook.com/me/picture?width=250&json=true endpoint access token profile pic link. in facebook's api explorer calling same endpoint token profile image url when call node.js endpoint handler binary data. part of response here.

����jfif���photoshop 3.08bim�gtc2xjton-90jqu9jfj83(bfbmd01000ac0030000b909000069110000fe120000dc14000069190000c02400002326000029280000872a0000fd3e0000��icc_prof 

how can url profile image instead of response.

not sure if still case on version of api you're using, used cause 301 redirect image if not passed correct parameter (despite api explorer suggests...) can check browser's network monitoring verify this.

there various sources this, including official facebook graph-api documentation, states:

by default edge return 302 redirect picture image. access data picture, please include redirect=false in query.

(source: https://developers.facebook.com/docs/graph-api/reference/user/picture/#reading )

along (older, similar) answers: https://stackoverflow.com/a/7881978/624590

you have couple options. 1 add redirect=false query param (per facebook documentation, above).

another option explicitly asking url adding additional query param, &fields=url (the answer linked above suggests &fields=picture, far can tell, that's out of date). if need height , width in response, add query: &fields=url,height,width. in experience facebook api, explicitly asking fields tends more reliable way go.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -