file get contents again not working alternative

前端 未结 2 489
北海茫月
北海茫月 2021-01-26 14:18

I tried the curl as the filegetcontents now working in php can any one give me the solution so solve it using curl here is the code

$userData = json_decode(file_         


        
相关标签:
2条回答
  • 2021-01-26 14:28

    How about this:

    $cFb = curl_init(
        'https://graph.facebook.com/me?access_token='.$token.'&fields=name,id'
    );
    curl_setopt($cFb, CURLOPT_RETURNTRANSFER, true);
    
    $userData = json_decode(curl_exec($cFb), true);
    
    curl_close($cFb);
    
    print($userData['id']).'<br/>';
    

    Although, as suggested by Abhik Chakraborty in the comments, it's probably worth looking into using the official Facebook PHP SDK. The SDK uses curl so it should work in your hosting environment.

    0 讨论(0)
  • 2021-01-26 14:39

    Try this:

    $json = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$token.'&fields=name,id'),true);
    $json_output = json_decode($json, true);
    

    Now you can get specific item like this:

    echo $json_output['id'];  
    
    0 讨论(0)
提交回复
热议问题