成功后如何保存Facebook访问令牌 [英] how to save facebook access token after success

查看:99
本文介绍了成功后如何保存Facebook访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户允许我的应用程序时,我会收到这种类型的成功网址:
HTTP://localhost/fbapp/app.php#access_token=AAAAALY8OpPABAM67auStdfgdfOdfgdfgdenqEt9QZCGD2a1h3iWFrhmNWqOf8l4a9RQ8tAJCM9y5QbYpsP6sT1g0ZCXDhtZCECZApGb& expires_in = 6604

when user allow my app i receive this type of success url:
http://localhost/fbapp/app.php#access_token=AAAAALY8OpPABAM67auStdfgdfOdfgdfgdenqEt9QZCGD2a1h3iWFrhmNWqOf8l4a9RQ8tAJCM9y5QbYpsP6sT1g0ZCXDhtZCECZApGb&expires_in=6604

我正在尝试$ _GET ['access_token']保存访问令牌,但无法正常工作,

i am trying $_GET['access_token'] to save access token, but it's not working,

我想知道如何从该URL获取访问令牌.

i want to know that how to get access token from this url..

推荐答案

从您对$ _GET的使用开始,我假设您正在谈论PHP.不幸的是,哈希标记从未发送到服务器.它们仅位于客户端,因此您需要使用一些JavaScript才能调用PHP脚本.

From your use of $_GET, I'm assuming you are talking about PHP. Unfortunately, hash tags are never sent to the server. They only live on the client side so you need to use some javascript to then make a call to a PHP script.

示例:

<script type="text/javascript">
var HashSearch = new function () {
   var params;

   this.set = function (key, value) {
      params[key] = value;
      this.push();
   };

   this.remove = function (key, value) {
      delete params[key];
      this.push();
   };


   this.get = function (key, value) {
       return params[key];
   };

   this.keyExists = function (key) {
       return params.hasOwnProperty(key);
   };

   this.push= function () {
       var hashBuilder = [], key, value;

       for(key in params) if (params.hasOwnProperty(key)) {
           key = escape(key), value = escape(params[key]); // escape(undefined) == "undefined"
           hashBuilder.push(key + ( (value !== "undefined") ? '=' + value : "" ));
       }

       window.location.hash = hashBuilder.join("&");
   };

   (this.load = function () {
       params = {}
       var hashStr = window.location.hash, hashArray, keyVal
       hashStr = hashStr.substring(1, hashStr.length);
       hashArray = hashStr.split('&');

       for(var i = 0; i < hashArray.length; i++) {
           keyVal = hashArray[i].split('=');
           params[unescape(keyVal[0])] = (typeof keyVal[1] != "undefined") ? unescape(keyVal[1]) : keyVal[1];
       }
   })();
}

$.ajax({
        type: "POST",
        url: '/store_access.php',
        data: 'access_token='+escape(HashSearch.get('access_token'),
        dataType: "html",
        success: function(response) {
            alert('Access Token Stored');
        }
    });
</script>

我在这里找到了HashSearch函数:从url中检索特定哈希标签的值

I found the HashSearch function here: Retrieve specific hash tag's value from url

此外,我假设在您的脚本发布中使用了jquery,但是您可以使用任何方法进行调用.您甚至可以使用包含令牌的网址将图片添加到正文.

Also, I assumed jquery on the post to your script, but you could use anything to make the call. You could even just add an image to the body with a url that includes the token.

这篇关于成功后如何保存Facebook访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆