简体   繁体   English

将短期访问令牌交换为长期有效

[英]Exchange short-lived access token for long-lived, not working

I am trying to exchange a short-lived user access token for a ling-lived, but getting an an error (in all.js): 我正在尝试将一个短暂的用户访问令牌交换为一个有效期,但是却出现错误(在all.js中):

ReferenceError: invalid assignment left-hand side ReferenceError:左侧的赋值无效

...TZCOZCkuZBxZAzVUSokiOJbXZAHhESJvuA97qXTpVbVj3P7AZDZD&expires=512326 ... TZCOZCkuZBxZAzVUSokiOJbXZAHhESJvuA97qXTpVbVj3P7AZDZD&期满= 512326

response.error.message: unknown error response.error.message:未知错误

Code: 码:

window.fbAsyncInit = function () {
           FB.init({
               appId: 'xxx', // App ID
               status: true, // check login status
               cookie: true, // enable cookies to allow the server to access the session
               xfbml: true,  // parse XFBML
               oauth: true
           });

           FB.login(function (response) {
                    if (response) {

                    var accessToken = response.authResponse.accessToken;

                    FB.getLoginStatus(function(response) {
                        if (response.status === 'connected') {

                            var accessToken = response.authResponse.accessToken;

                            var OauthParams = {};
                            OauthParams['client_id'] = 'xxx';
                            OauthParams['client_secret'] = 'xxx';
                            OauthParams['grant_type'] = 'fb_exchange_token';
                            OauthParams['fb_exchange_token'] = accessToken;
                            OauthParams['response_type'] = 'token';
                            console.log(accessToken);

                            FB.api('/oauth/access_token', 'post', OauthParams, function(response) {
                                if (!response || response.error) {
                                    console.log(response.error.message);
                                } 
                                else {
                                    console.log(response.accesstoken);
                                }
                            });        
                        }
                    });
                    };

           }, { scope: 'manage_pages' });

       };


}

(function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
}(document));

Anyone has an idea? 有人有主意吗?

Thanks, /M 谢谢,/ M

according to scenario 4 of the documentation you have to send a GET request to 根据文档的场景4,您必须将GET请求发送至

https://graph.facebook.com/oauth/access_token?
    client_id=APP_ID&
    client_secret=APP_SECRET&
    grant_type=fb_exchange_token&
    fb_exchange_token=EXISTING_ACCESS_TOKEN

maybe the problem is that you are using POST request, but I am not sure 也许问题是您使用的是POST请求,但我不确定

PS I wouldn't recommend to use APP_SECRET on client side PS我不建议在客户端使用APP_SECRET

I had a similar issue running tests from a FB Javascript SDK client. 我从FB Javascript SDK客户端运行测试时遇到类似的问题。 The problem on my end was that SDK was tripping handling the access_token in fb_exchange_token . 我的问题是,SDK在处理fb_exchange_token的access_token时fb_exchange_token Changing just last three characters in this access token string made the error go away. 仅更改此访问令牌字符串中的最后三个字符即可使错误消失。 Of course, this doesn't help solving the problem, but at least this is where the issue was in my case. 当然,这无助于解决问题,但至少在我看来这就是问题所在。

Since these calls must be made from a server anyway, I am not going to proceed troubleshooting this further. 由于无论如何都必须从服务器发出这些调用,因此我将不进行进一步的故障排除。

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

相关问题 Facebook 图 API 长寿命令牌 - Facebook Graph API Long-Lived Token 从 Instagram 基本显示 API 获取长期访问令牌的问题 - Troubles Fetching a Long-lived Access Token from the Instagram Basic Display API 使用Firefox调试短暂的Web工作者 - Debugging short-lived web workers with Firefox 刷新长寿命访问令牌端点是否在 2021 年工作? - Is refreshing long lived access token endpoint working in 2021? 如何从vkontakte获取长期访问令牌? - How to get long lived access token from vkontakte? 使用Apache / PHP / Javascript的长期连接(异步服务器推送)? - Long-lived connections (asynchronous server push) with Apache/PHP/Javascript? Recoil:将长期存在的客户端 object 传递给选择器 - Recoil: Passing a long-lived client object to a selector 如何建立与jQuery的长期连接以进行推送通知? - How can I establish a long-lived connection with jQuery for push notification? chrome扩展中具有长期连接的“尝试使用断开连接的端口对象” - “Attempting to use a disconnected port object” with Long-lived connections in chrome extension 在 React Base chrome 扩展中使用长寿命连接时无法获取状态值 - Unable to get state value in when using long-lived connection in react base chrome extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM