criso / fbgraph

NodeJs module to access the facebook graph api
http://criso.github.io/fbgraph/
1.09k stars 177 forks source link

Does this package have graph.setAppsecretTime(appsecret_time)? #132

Open harishankards opened 6 years ago

harishankards commented 6 years ago

With the docs, I can see that there is no feature as of now. With facebook's graph is needing appsecret_time as a required parameter, how can we achieve that?

as we get error { error: { message: 'API calls with a community access token require an appsecret_proof and an appsecret_time argument', type: 'GraphMethodException', code: 100, fbtrace_id: 'EdXhSAgyCdy' } }

You have graph.setAppsecret(app_secret) already. Please tell me how to resolve the appsecret_time dependency.

ffflabs commented 6 years ago

The appsecret_proof is generated on:

https://github.com/criso/fbgraph/blob/894fa3153d745ac0de5d37b5ca905c98f98e8f68/lib/graph.js#L121-L128

It would need to be changed to:

  // add appsecret_proof and appsecret_time to the url
  var appsecretTime = Math.floor(Date.now() / 1000);
  if (sessionAccessToken && appSecret && url.indexOf('appsecret_proof') === -1) {
    var hmac = crypto.createHmac('sha256', appSecret);
    hmac.update(sessionAccessToken + '|' + appsecretTime);

    url += ~url.indexOf('?') ? '&' : '?';
    url += "appsecret_proof=" + hmac.digest('hex');
    url += "&appsecret_time=" + appsecretTime;
  }

however, it seems this package is no longer mantained, so I wonder if it's worth making a pull request.