khashnan / timthumb

Automatically exported from code.google.com/p/timthumb
0 stars 0 forks source link

facebook graph images #275

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I try to get timthumb to resize main images of facebook profiles.

A TimThumb error has occured

The following error(s) occured:
The remote file is not a valid image.

Timthumb works fine, but not with facebook graph.
what can it be? heeeeelp!?

URL getting error sample:
http://republicarayada.com.mx/timthumb.php?src=https://graph.facebook.com/100000
043114207/picture?type=normal&h=104&w=83&zc=1

I already have set:

define ('ALLOW_EXTERNAL', TRUE);
$ALLOWED_SITES = array (
'facebook.com',
);

Original issue reported on code.google.com by gpin...@gmail.com on 21 Oct 2011 at 6:46

GoogleCodeExporter commented 8 years ago
i have already solved!
the error is because the facebook redirect to get the image.
you have to provide to timthumb, the final url.

Original comment by gpin...@gmail.com on 21 Oct 2011 at 7:19

GoogleCodeExporter commented 8 years ago
yeah, use this function to get this url.

    public function getRealUrl($photoLink) {            
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->header);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, false);
        curl_setopt($this->curl, CURLOPT_HEADER, false);
        curl_setopt($this->curl, CURLOPT_USERAGENT, $this->useragent);
        curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($this->curl, CURLOPT_TIMEOUT, 15);
        curl_setopt($this->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($this->curl, CURLOPT_URL, $photoLink);
        //this assumes your code is into a class method, and uses $this->readHeader as the callback //function
        curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, array(&$this,'readHeader'));
        $response = curl_exec($this->curl);
        if(!curl_errno($this->curl)) {
            $info = curl_getinfo($this->curl);
//            var_dump($info);
             if($info["http_code"] == 302) {
                 $headers = $this->getHeaders();
                 if(isset($headers['fileUrl'])) {
                     return $headers['fileUrl'];
                 }
             }
        }
        return false;
    }

Original comment by p.ba...@eminus.pl on 24 Oct 2011 at 7:15

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
how to use the above code kindly explain with example.

Original comment by firdaus....@pyrspective.com on 24 Feb 2012 at 1:29

GoogleCodeExporter commented 8 years ago
the code in comment 2 is the best solution for this.

Original comment by BinaryMoon on 27 Sep 2013 at 9:36