gpt4 book ai didi

node.js - NodeJS Facebook 用户源订阅 : Invalid OAuth access token

转载 作者:太空宇宙 更新时间:2023-11-04 00:58:01 24 4
gpt4 key购买 nike

我快要抓狂了(作为一名充满热情的开发人员,应该如此),所以希望我能在这方面得到一些帮助。在阅读了大量论坛并筛选 Facebook 文档后,这里是尝试订阅用户源的日志文件。我真的只需要知道我正在运行的底层 API 集在理论上是否应该工作。这是我的日志:

*********************************************************
makeRequest - Host: graph.facebook.com - Path: /v2.2/{ app_id }/subscriptions?object=user
*********************************************************
Type: DELETE
*********************************************************
Wed Feb 25 2015 12:52:15 GMT+0000 (UTC) Server is listening on port 81
*********************************************************
makeRequest - Host: graph.facebook.com - Path: /oauth/access_token?client_id={ app_id }&client_secret={ app_secret }&grant_type=client_credentials
*********************************************************
Type: GET
*********************************************************
App Access Token: { app_token }
*********************************************************
makeRequest - Host: graph.facebook.com - Path: /v2.2/{ app_id }/subscriptions?&object=user&fields=feed&callback_url={ uri_encoded_ callback_url }&verify_token={ verify_token }&access_token={ app_token }
*********************************************************
Type: POST
*********************************************************
Success: {"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190}}

因此,我首先尝试删除当前事件的所有订阅,然后使用 API 来获取新的应用程序访问 token ,最后进行新的订阅。这是我初始化整个过程的函数:

function subscribe_facebook(http,https) {
var oauth_obj = getOauthObj('facebook');

// First Delete
var url = oauth_obj.subscription_url;
var host = splitUrl(url,"host");
var path = splitUrl(url,"path");

path += "?object=user";

makeRequest(http,host,path,80,'DELETE',function(ret){
// Get App Access Token
url = oauth_obj.access_token_url;
host = splitUrl(url,"host");
path = splitUrl(url,"path");

path += "?client_id=" + oauth_obj.app_id;
path += "&client_secret=" + oauth_obj.app_secret;
path += "&grant_type=client_credentials";

makeRequest(https,host,path,443,'GET',function(ret){
facebook_app_token = ret.toString().split('|');
facebook_app_token = facebook_app_token[1];
consoleLogger("App Access Token: " + facebook_app_token);

subscribe(https,'facebook',443,'POST',facebook_app_token,myServer);
});
});
}

这是它输入的订阅函数:

function subscribe(http,type,port,method,access_token,myServer) {
var oauth_obj = getOauthObj(type);
var sub_post_data = "";
switch (type) {
case "facebook":
sub_post_data =
"&object=" + "user"+
"&fields=" + "feed"+
"&callback_url=" + encodeURIComponent(myServer + "/" + type) +
"&verify_token=" + "*****" +
"&access_token=" + access_token
break;
}

var host = splitUrl(oauth_obj.subscription_url,"host");
var path = splitUrl(oauth_obj.subscription_url,"path");
path += "?" + sub_post_data;

makeRequest(http,host,path,port,method,function(ret) {
consoleLogger("Success: " + ret);
});
}

我创建了另一个函数来维护社交媒体变量:

function getOauthObj(type) {
var obj = {};
var authorize_url = "";
var access_token_url = "";
var request_token_url = "";
var subscription_url = "";

var app_id = "";
var app_secret = "";

var main_domain = "";
var scope = "";

switch (type) {
case "facebook":
app_id = '*****';
app_secret = '**********';

main_domain = 'https://graph.facebook.com/';
authorize_url = 'https://www.facebook.com/dialog/oauth';
access_token_url = main_domain + 'oauth/access_token';
request_token_url = main_domain + '2.2/me';
subscription_url = main_domain + "v2.2/" + app_id + "/subscriptions";
scope = 'read_stream';
break;
}
obj.main_domain = main_domain;

obj.authorize_url = authorize_url;
obj.access_token_url = access_token_url;
obj.request_token_url = request_token_url;
obj.subscription_url = subscription_url;

obj.app_id = app_id;
obj.app_secret = app_secret;

return obj;
}

由于 OAuth 无效,我假设我没有将正确的参数传递给 oauth API 来执行此操作或不这样做 - 有人可以引导我走向正确的方向吗?

最佳答案

好的,现在已经修复了。我在一些论坛上读到过有关不同 Facebook API 的详细信息,其中详细介绍了使用应用程序 ID,与管道连接,然后可以使用应用程序 secret 来代替访问 token ,但我不认为这可以在这里使用,但事实证明可以!

*********************************************************
makeRequest - Host: graph.facebook.com - Path: /v2.2/{ app_id }/subscriptions?&object=user&fields=feed&callback_url={ callback_url }&verify_token={ verify_token }&access_token={ app_id }|{ app_secret }

希望这对某人有帮助。

干杯。

关于node.js - NodeJS Facebook 用户源订阅 : Invalid OAuth access token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28719916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com