Facebook Auth with high traffic sites: empty access tokens, empty /me

后端 未结 3 1072
攒了一身酷
攒了一身酷 2021-01-17 04:13

We have an app running on a Facebook tab at the moment which is receiving a good deal of traffic. People are signing up every few seconds, and most are successful. However I

3条回答
  •  忘掉有多难
    2021-01-17 04:40

    I think it's because php_openssl extension is either absent or disabled. See this question to enable it. Or you can use cURL. Take fb_ca_chain_bundle.crt from PHP SDK official (or set CURLOPT_SSL_VERIFYPEER to false):

    $base_url = 'https://graph.facebook.com/oauth/access_token';
    $params   = array();
    
    $params['client_id']     = $client_id;
    $params['client_secret'] = $client_secret;
    $params['redirect_uri']  = $redirect_uri;
    $params['code']          = $code;
    
    $options = array(
        CURLOPT_SSL_VERIFYHOST => 2,
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_CAINFO         => __DIR__ .'/fb_ca_chain_bundle.crt',
        CURLOPT_RETURNTRANSFER => true,
        CURLINFO_HEADER_OUT    => false,
        CURLOPT_HEADER         => false,
        CURLOPT_URL            => $base_url . '?' . http_build_query($params),
     );
    
     // Init cURL and send the request
     $ch = curl_init();
     curl_setopt_array($ch, $params);
    
     $result = curl_exec($ch);
     $infos  = curl_getinfo($ch);
    
     curl_close($ch);
     var_dump($result, $infos);
    

    EDIT: i warn you this is a quick copy and paste from my code so you would double check $options.

提交回复
热议问题