Issue using the Meteor's HTTP.call() for retrieve the user's facebook friend's

Hi,

i’m new to meteor so i would like your help :slight_smile:

i want to retrieve the user’s friends from facebook, using the HTTP.call().

for the outh im using the account-facebook and accounts-ui and they are working great (the user was created + i got his access token etc. also, i defined on accounts…ui.config to pull ‘user_friends’ and the access was granted).

now, i want to pull the friends on each login (i want to get updats on each login, i know i need to prolong the access token life, but i’ll deal with that later).

so, on the client -

Accounts.onLogin(function(){
  // Given a userId, get the user's Facebook access token
  const userId = Meteor.userId();
  const user = Meteor.users.findOne(userId);
  const fbAccessToken = user.services.facebook.accessToken;
  console.log(fbAccessToken);
  console.log('will now call getFriendsData')
 // calling the HTTP.call() with the access token. 
  Meteor.call('getFriendsData', fbAccessToken);
  console.log('getFriendsData - onLogin');
});

from what i see i dont get a issue here.

on the server -

Meteor.methods({
    getFriendsData: function(fbAccessToken) {
       var fb = fbAccessToken;
       var data = HTTP.call("GET", 'https://graph.facebook.com/', ['/me/photos'] [fb]);
       return data;
       console.log(data);
    }
});

i added the [bf] because on facebook its noted that calls should end with the access token. but not sure i did it correctly…

i get the following error:

any ideas?
thanks!!

Exception while invoking method ‘getFriendsData’ Error: failed [400] {“error”:{“message”:“Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/g
raph-api”,“type”:“GraphMethodException”,“code”:100,“fbtrace_id”:“FLb7m0Gr+BG”}}
I20170703-17:48:01.714(3)? at Object.Future.wait (/Users/amir/.meteor/packages/meteor-tool/.1.5.0.hye0rn++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:449:15)
I20170703-17:48:01.715(3)? at Object.call (packages/meteor.js:213:24)
I20170703-17:48:01.716(3)? at [object Object].Meteor.methods.getFriendsData (server/main.js:16:24)
I20170703-17:48:01.718(3)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1737:12)
I20170703-17:48:01.720(3)? at packages/ddp-server/livedata_server.js:719:19
I20170703-17:48:01.721(3)? at [object Object]..extend.withValue (packages/meteor.js:1122:17)
I20170703-17:48:01.721(3)? at packages/ddp-server/livedata_server.js:717:40
I20170703-17:48:01.722(3)? at [object Object].
.extend.withValue (packages/meteor.js:1122:17)
I20170703-17:48:01.723(3)? at packages/ddp-server/livedata_server.js:715:46
I20170703-17:48:01.723(3)? at [object Object]._.extend.protocol_handlers.method (packages/ddp-server/livedata_server.js:689:23)
I20170703-17:48:01.724(3)? - - - - -
I20170703-17:48:01.725(3)? at makeErrorByStatus (packages/http/httpcall_common.js:13:10)
I20170703-17:48:01.726(3)? at Request._callback (packages/http/httpcall_server.js:113:17)
I20170703-17:48:01.726(3)? at Request.self.callback (/Users/amir/.meteor/packages/http/.1.2.12.ne7y4p++os+web.browser+web.cordova/npm/node_modules/request/request.js:200:22)
I20170703-17:48:01.727(3)? at emitTwo (events.js:87:13)
I20170703-17:48:01.727(3)? at Request.emit (events.js:172:7)
I20170703-17:48:01.728(3)? at Request. (/Users/amir/.meteor/packages/http/.1.2.12.ne7y4p++os+web.browser+web.cordova/npm/node_modules/request/request.js:1067:10)
I20170703-17:48:01.729(3)? at emitOne (events.js:82:20)
I20170703-17:48:01.729(3)? at Request.emit (events.js:169:7)
I20170703-17:48:01.730(3)? at IncomingMessage. (/Users/amir/.meteor/packages/http/.1.2.12.ne7y4p++os+web.browser+web.cordova/npm/node_modules/request/request.js:988:12)
I20170703-17:48:01.732(3)? at emitNone (events.js:72:20)

Could you please edit your post and wrap your code in triple backticks:

```
like
this
```

sure, didnt know about it :slight_smile:

thanks!

I suggest you have a good read of the documentation for HTTP

The basic pattern HTTP.call(method, url, [options], [asyncCallback]) is very different to what you’ve passed it. (square brackets indicate an optional argument, not to literally wrap arguments in an array)
What you need is to add the access token to the url as a parameter like so:

var data = HTTP.call("GET", 'https://graph.facebook.com/me/photos', { params: { access_token: fb } });
1 Like

Wow, amazing!

so I simply didn’t understand the HTTP method.

thank you very much, it helped a lot!

1 Like