Facebook graph api Facebook Javascript SDK扩展访问令牌获取;无效的OAuth访问令牌";-190-“;OAutheException“;
我尝试使用JavascriptSDK获取访问令牌,然后将该访问令牌扩展60天。我从响应中得到如下响应错误:Facebook graph api Facebook Javascript SDK扩展访问令牌获取;无效的OAuth访问令牌";-190-“;OAutheException“;,facebook-graph-api,oauth,facebook-javascript-sdk,facebook-access-token,Facebook Graph Api,Oauth,Facebook Javascript Sdk,Facebook Access Token,我尝试使用JavascriptSDK获取访问令牌,然后将该访问令牌扩展60天。我从响应中得到如下响应错误:Object{message=“无效的OAuth访问令牌。”,type=“OAuthException”,code=190} 我的期望: 获取过期60天的新访问令牌 控制台到屏幕 我的代码: window.onload = function() { var isLogin = true; FB.init({appId:422642254433770, cookie:true, statu
Object{message=“无效的OAuth访问令牌。”,type=“OAuthException”,code=190}
我的期望:
window.onload = function() {
var isLogin = true;
FB.init({appId:422642254433770, cookie:true, status:true, xfbml:true });
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and connected to your
// app, and response.authResponse supplies
// the user’s ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
var accessTokenOld = response.authResponse.accessToken;
//Extend access token
var OauthParams = {};
OauthParams['client_id'] = '//REMOVED APP ID';
OauthParams['client_secret'] = '//REMOVED APP SECRET';
OauthParams['grant_type'] = 'fb_exchange_token';
OauthParams['fb_exchange_token'] = 'accessToken';
OauthParams['response_type'] = 'token';
console.log("Old accessToken => " + accessToken);
FB.api('/oauth/access_token', 'post', OauthParams, function(response) {
console.log(response);
if (!response || response.error) {
console.log(response.accesstoken);
} else {
console.log("Lay new access token bi loi " + response.error.message);
}
});
}
});
};
我试着在没有任何线索的情况下3天内到处寻找这个麻烦。我想有人有经验吗?请帮忙
非常感谢如果您在FB应用的高级设置中启用了“删除脱机访问权限”,则默认情况下,您的所有访问令牌将使用60天 我们最近遇到了同样的问题,这解决了问题
希望这有帮助 我找到了一个简单的解决方案,可以使用Jquery valide获得长达2个月的扩展访问令牌 要传递到URL的变量:
var accessToken = 'CURRENT_ACCESS_TOKEN';
var appid = 'APPID';
var appsecret = 'APPSECRET';
您的URL应指向
var exchangeUrl = "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&fb_exchange_token="+accessToken+"&client_id="+appid+"&client_secret="+appsecret;
作为
$.ajax({
type: "GET",
url: exchangeUrl,
success: function(data)
{
extended = data.split('=');
extendedAT = extended['1'].replace('&expires','');
alert(extendedAT);
}
});
在客户端中这样做是一个坏主意,因为要求在实际客户端中包含应用程序机密,这是非常危险的。最好在您的服务器上调用一个单独处理此问题的端点,以便应用程序机密保留在您的受控环境中 当你把你试图交换的令牌放进去验证它是否正确时?是的,我测试了返回令牌,并在接下来的2小时内到期。返回令牌没有问题,所以我不知道为什么会发生此错误。我的错误:OOauthParams['fb_exchange_token']='accessToken';这将起作用:OOauthParams['fb\u交换\u令牌']=accessToken;你不应该在前端脚本上传递应用程序机密。。。不安全