0

So I have made a couple of post requests to FB's API and they work fine, one of the POST actually spits out in the console the id of the user I'm supposed to pass if I want to get extra info about the profile in case I want to reuse it to post it somewhere else usign a different API.

So the idea is to get the user profile to reuse it.

Following the documentation: HERE

It's all good when done manually, because I get the info that I need by doing:

curl -X GET "https://graph.facebook.com/v2.6/<USER_ID>?fields=first_name,last_name,profile_pic,locale,timezone,gender&access_token=PAGE_ACCESS_TOKEN"

However if do in my code:

function getUserProfile (sender) {
    request({
         method : "GET",
         uri    : "https://graph.facebook.com/v2.6/" + sender + "?",
         qs     : {
            fields:"first_name,last_name,profile_pic,locale,timezone,gender",
            access_token : FB_PAGE_ACCESS_TOKEN   
         },
         json   : true
     }
 );
}
console.log('fb user GET Request: ', request);

I get a complaint about the uri not being passed correctly and I don't get nothing printed into console:

Here is the log:

> node app.js
 fb user GET Request:  function request(uri, options, callback) {
  if (typeof uri === 'undefined') {
     throw new Error('undefined is not a valid uri or options object.')
  } 
  var params = initParams(uri, options, callback) 
  if (params.method === 'HEAD' && paramsHaveRequestBody(params)) {
     throw new Error('HTTP HEAD requests MUST NOT include a request body.')
   } 
   return new request.Request(params)
 }

What am I missing? Any pointers would be great.

Edit:

I have found a SO post HERE and tried the solution given but the log is still invisible.

I am using heroku as server but I cannot see any objects from a GET request in the logs. I should be able to see what I'm getting, by console.log right?

These are the requires made:

const async     = require("async");
const uuid      = require("node-uuid");
const request   = require('request');

const apiai = require('apiai');
const express = require('express');
const bodyParser = require('body-parser');
const JSONbig = require('json-bigint');
Community
  • 1
  • 1
Tmute
  • 43
  • 1
  • 8

1 Answers1

0

Looks like you are defining he options for the request object, however it is not clear how you are executing the http request.

Can you try something like?

options = {
         method : "GET",
         uri    : "https://graph.facebook.com/v2.6/" + sender + "?",
         qs     : {
            fields:"first_name,last_name,profile_pic,locale,timezone,gender",
            access_token : FB_PAGE_ACCESS_TOKEN   
         },
         json   : true
     }

Then use this option to execute the request

request(options, callback).end()
Santanu Dey
  • 2,900
  • 3
  • 24
  • 38
  • can you please elaborate on the being clear on the request? I'm trying to get the user name and last name and send to another app but the response is not available, or if it is I cannot see it in my logs. – Tmute Aug 03 '16 at 14:23
  • I understood from your question that you are getting undefined when trying to make an HTTP request to facebook API. I was not sure which http client are you using to make these requests? FB sdk for node? some other http client library. The specific code would change accordingly. What I suggested here was to use something like: https://docs.nodejitsu.com/articles/HTTP/clients/how-to-create-a-HTTP-request/ – Santanu Dey Aug 04 '16 at 00:33
  • I used the request module from node. Please @santanu see edit on post – Tmute Aug 04 '16 at 22:47