只获取特定代码

时间:2017-06-10 15:50:25

标签: php facebook

在我的网站中,用户使用访问令牌获取自己的密码并在我的网站中提交该代码,并且从这个代码我只想在php的帮助下获取访问令牌... 检查此 ScreenShoot ss.jpg

访问令牌示例 {"session_key":"5.TVJlCXvhgqdhpA.1497109242.26-100007001746590","uid":100007001746590,"secret":"80cc3dc2ba89e635dcf84b41d6efcc38","access_token":"EAAAAAYsX7TsBAEa6qMaCj1qCgnOKFHBcfu76C6PrUdK1LnIh39jmabZAdVWmQLO3Ol64ZCXY4388DBfUwksxONGXE5dUY0mK9M07aszl5Qvs8ccqQ39xLEsK2gc1RUJQ0Kqy1ror7R8EPHZCX6pOzX0o4oQAJ1kOq8Oz0n0GysK64ebCsDEokwG36j1awnYaDoJPvOn2AZDZD","machine_id":"-hI8WaLcNeEVUSPuxcEpmhQU","confirmed":true}

我还尝试通过分离所有这些代码来分隔访问令牌,但这实际上不起作用

这是我的php脚本

if(isset($_POST['submit'])) {
    $token2 = $_POST['token'];
    if(preg_match("'access_token=(.*?)&expires_in='", $token2, $matches)){
        $token = $matches[1];
            }
    else{
        $token = $token2;
    }
        $extend = get_html("https://graph.facebook.com/me/permissions?access_token="  . $token);

如何做到这一点,并提前感谢

2 个答案:

答案 0 :(得分:1)

请尝试使用php将此json解析为数组,然后您可以收集所需的令牌属性并继续验证流程。此解决方案有一个相关链接:How to convert JSON string to array

有一个基本的例子:

$your_submit_data = '{"session_key":"5.TVJlCXvhgqdhpA.1497109242.26-100007001746590","uid":100007001746590,"secret":"80cc3dc2ba89e635dcf84b41d6efcc38","access_token":"EAAAAAYsX7TsBAEa6qMaCj1qCgnOKFHBcfu76C6PrUdK1LnIh39jmabZAdVWmQLO3Ol64ZCXY4388DBfUwksxONGXE5dUY0mK9M07aszl5Qvs8ccqQ39xLEsK2gc1RUJQ0Kqy1ror7R8EPHZCX6pOzX0o4oQAJ1kOq8Oz0n0GysK64ebCsDEokwG36j1awnYaDoJPvOn2AZDZD","machine_id":"-hI8WaLcNeEVUSPuxcEpmhQU","confirmed":true}';

$your_array = json_decode($your_submit_data, TRUE);

echo($your_array['access_token']);

最佳,

答案 1 :(得分:0)

您可以使用此代码仅从JSON代码中获取access_token

if(isset($_POST['submit'])) {
    $token2 = $_POST['token'];
    $obj = json_decode($token2);
    echo "Access Token is: <br />". $obj->{'access_token'}; // You can remove it or use this value
    $token = $obj->{'access_token'};
    $extend = get_html("https://graph.facebook.com/me/permissions?access_token="  . $token);
}