PHP & Facebook: facebook-debug a URL using CURL and Facebook debugger

后端 未结 1 1650
情话喂你
情话喂你 2020-12-20 00:11

Facts: I run a simple website that contains articles, articles dynamically acquired by scraping third-party websites/blogs etc (new articles arrive to my we

相关标签:
1条回答
  • 2020-12-20 00:38

    You can debug a graph object using Facebook graph API with PHP-cURL, by doing a POST to

    https://graph.facebook.com/v1.0/?id={Object_URL}&scrape=1
    

    to make thing easier, we can wrap our debugger within a function:

    function facebookDebugger($url) {
    
            $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v1.0/?id='. urlencode($url). '&scrape=1');
                  curl_setopt($ch, CURLOPT_POST, 1);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            $r = curl_exec($ch);
            return $r;
    
    }
    

    though this will update & clear Facebook cache for the passed URL, it's a bit hard to print out each key & its content and avoid errors in the same time, however I recommended using var_dump() or print_r() OR PHP-ref

    usage with PHP-ref

    r( facebookDebugger('http://retrogramexplore.tumblr.com/') );
    

    PHP-ref output

    0 讨论(0)
提交回复
热议问题