简体   繁体   English

facebook 图 api node.js 无效 appsecret_proof

[英]facebook graph api node.js invalid appsecret_proof

this is my first post so please go easy on me!这是我的第一篇文章,所以请放轻松!

I am a beginning developer working with javascript and node.js.我是一名使用 javascript 和 node.js 的初级开发人员。 I am trying to make a basic request from a node js file to facebook's graph API.我正在尝试从节点 js 文件向 Facebook 的图形 API 发出基本请求。 I have signed up for their developer service using my facebook account, and I have installed the node package for FB found here ( https://www.npmjs.com/package/fb ).我已经使用我的 facebook 帐户注册了他们的开发人员服务,并且我已经安装了在这里找到的 FB 节点包( https://www.npmjs.com/package/fb )。 It looks official enough.它看起来足够正式。

Everything seems to be working, except I am getting a response to my GET request with a message saying my appsecret_proof is invalid.一切似乎都在工作,除了我收到对我的 GET 请求的响应,并显示一条消息说我的 appsecret_proof 无效。

Here is the code I am using (be advised the sensitive info is just keyboard mashing).这是我正在使用的代码(请注意敏感信息只是键盘混搭)。

let https = require("https");
var FB = require('fb');

FB.options({
    version: 'v2.11',
    appId: 484592542348233,
    appSecret: '389fa3ha3fukzf83a3r8a3f3aa3a3'
});


FB.setAccessToken('f8af89a3f98a3f89a3f87af8afnafmdasfasedfaskjefzev8zv9z390fz39fznabacbkcbalanaa3fla398fa3lfa3flka3flina3fk3anflka3fnalifn3laifnka3fnaelfafi3eifafnaifla3nfia3nfa3ifla');

console.log(FB.options());

FB.api('/me',
    'GET',
    {
        "fields": "id,name"
    },
    function (res) {
        if(!res || res.error) {
            console.log(!res ? 'error occurred' : res.error);
            return;
        }
        console.log(res);
        console.log(res.id);
        console.log(res.name);
    }
);

The error I am getting reads:我收到的错误是:

{ message: 'Invalid appsecret_proof provided in the API argument',
  type: 'GraphMethodException',
  code: 100,
  fbtrace_id: 'H3pDC0OPZdK' }

I have reset my appSecret and accessToken on the developer page and tried them immediately after resetting them.我已经在开发者页面上重置了我的 appSecret 和 accessToken,并在重置后立即尝试了它们。 I get the same error, so I don't think that stale credentials are the issue.我遇到了同样的错误,所以我不认为陈旧的凭据是问题所在。 My我的

 console.log(FB.options()) 

returns an appropriate looking object that also contains a long hash for appSecretProof as expected.返回一个合适的外观对象,该对象还包含预期的 appSecretProof 的长哈希值。 I have also tried this code with a number of version numbers in the options (v2.4, v2.5, v2.11, and without any version key).我还尝试了此代码,其中包含选项中的多个版本号(v2.4、v2.5、v2.11,并且没有任何版本密钥)。 Facebook's documentation on this strikes me as somewhat unclear. Facebook 在这方面的文档让我觉得有些不清楚。 I think I should be using v2.5 of the SDK (which the node package is meant to mimic) and making requests to v2.11 of the graph API, but ???我想我应该使用 SDK 的 v2.5(节点包旨在模仿)并向图形 API 的 v2.11 发出请求,但是??? In any case, that wouldn't seem to explain the issue I'm having.无论如何,这似乎无法解释我遇到的问题。 I get a perfectly good response that says my appSecretProof is invalid when I don't specify any version number at all.我得到了一个非常好的回应,说当我根本没有指定任何版本号时,我的 appSecretProof 无效。

The node package for fb should be generating this appSecretProof for me, and it looks like it is doing that. fb 的节点包应该为我生成这个 appSecretProof,看起来它正在这样做。 My other info and syntax all seem correct according to the package documentation.根据包文档,我的其他信息和语法似乎都是正确的。 What am I missing here?我在这里缺少什么? Thank you all so much in advance.非常感谢大家。

looks like you have required the appsecret_proof for 2 factor authorization in the advance setting in your app.看起来您在应用程序的高级设置中需要 appsecret_proof 进行 2 因素授权。

Access tokens are portable.访问令牌是可移植的。 It's possible to take an access token generated on a client by Facebook's SDK, send it to a server and then make calls from that server on behalf of the client.可以获取由 Facebook 的 SDK 在客户端生成的访问令牌,将其发送到服务器,然后代表客户端从该服务器进行调用。 An access token can also be stolen by malicious software on a person's computer or a man in the middle attack.访问令牌也可能被个人计算机上的恶意软件或中间人攻击窃取。 Then that access token can be used from an entirely different system that's not the client and not your server, generating spam or stealing data.然后,可以从一个完全不同的系统(不是客户端也不是您的服务器)使用该访问令牌,从而生成垃圾邮件或窃取数据。

You can prevent this by adding the appsecret_proof parameter to every API call from a server and enabling the setting to require proof on all calls.您可以通过将appsecret_proof参数添加到来自服务器的每个 API 调用并启用该设置以要求对所有调用进行证明来防止这种情况。 This prevents bad guys from making API calls with your access tokens from their servers.这可以防止坏人使用您的访问令牌从他们的服务器进行 API 调用。 If you're using the official PHP SDK, the appsecret_proof parameter is automatically added.如果您使用的是官方 PHP SDK,则会自动添加 appsecret_proof 参数。

Please refer the below url to generate the valid appsecret_proof,and add it to each api call请参考以下 url 生成有效的 appsecret_proof,并将其添加到每个 api 调用中

https://developers.facebook.com/docs/graph-api/securing-requests https://developers.facebook.com/docs/graph-api/securing-requests

I had to deal with the same issue while working with passport-facebook-token , I finally released that the problem had nothing to have with the logic of my codebase or the app configuration.我在使用passport-facebook-token时不得不处理同样的问题,我终于发布了这个问题与我的代码库或应用程序配置的逻辑无关。

I had this error just because I was adding intentionally an authorization Header to the request.我之所以遇到此错误,只是因为我有意向请求添加了授权标头。 so if you are using postman or some other http client just make sure that the request does not contain any authorization Header.因此,如果您使用邮递员或其他一些 http 客户端,请确保请求不包含任何授权标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM