Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

php - Facebook cookie and oauth 2.0 changes

This function used to work for me until the other day when facebook decided to enforce some changes.

    function get_facebook_cookie() {
    $app_id             = '[MyAppID]';
    $application_secret = '[MyAppSecrect]';

    if(isset($_COOKIE['fbs_' . $app_id])){
        $args = array();
        parse_str(trim($_COOKIE['fbs_' . $app_id], '"'), $args);
        ksort($args);
        $payload = '';
        foreach ($args as $key => $value) {
                if ($key != 'sig') {
                $payload .= $key . '=' . $value;
                }
        }
        if (md5($payload . $application_secret) != $args['sig']) {
                return null;
        }
        return $args;
        } else {
         return null;
        }
}

I was the able to get the FB users access token as easily as

$cookie['access_token']

Now it doesn't seem that I'm able to retrieve this info anymore.

I was successfully (easily) able to make the required changes to my javascript code, but I'm kind of stumped on the php side. As a quick side note I'm using codeigniter and I've had a lot of trouble trying to get the FB PHP SDK to play nice, also I havne't seen any examples of integrating the PHP 3 SDK into codeigniter so I'm looking for a quick and dirty solution that will allow me to get the access token from the cookie thus allowing me to use the following call to Facebooks API:

'https://api.facebook.com/method/friends.getAppUsers?access_token=' . $cookie['access_token'];

Any help is greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

it's because facebook change cookie name from fbs_ to fbsr_.

But there was more changes. Just follow this steps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...