0

I need to download (by php: curl, file_get_contents...) the post full picture to site folders.

I can get the post item data, even the full_picture url but when I want to download it by wget or curl the server responds with an 403.

If I try to download that url by browser, no problem, I can see it.

https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457&oe=5748C6D2

But if I try from curl or wget I get a 401 response

wget https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457&oe=5748C6D2

[1] 9988
[2] 9989

$ converted 'https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457' (ANSI_X3.4-1968) -> 'https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457' (UTF-8)
--2016-01-22 15:20:39--  https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457
Resolving scontent.xx.fbcdn.net (scontent.xx.fbcdn.net)... 31.13.83.4, 31.13.83.4
Connecting to scontent.xx.fbcdn.net (scontent.xx.fbcdn.net)|31.13.83.4|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2016-01-22 15:20:39 ERROR 403: Forbidden.

I've tried also appending the access token to the path:

...&access_token=XXXXXXXX

This is the json post item:

stdClass Object
(
    [id] => 396231587217143_531401453700155
    [created_time] => 2016-01-11T13:21:37+0000
     ...
    [picture] => https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s130x130/12525704_987920591279679_1409522552_n.jpg?oh=34e4a1b419bb842c5f84441f9a781745&oe=574676AE
    [full_picture] => https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457&oe=5748C6D2
    [attachments] => stdClass Object
        (
            [data] => Array
                (
                    [0] => stdClass Object
                        (
                            [media] => stdClass Object
                                (
                                    [image] => stdClass Object
                                        (
                                            [height] => 405
                                            [src] => https://scontent.xx.fbcdn.net/hvthumb-xta1/v/t15.0-10/s720x720/12525704_987920591279679_1409522552_n.jpg?oh=33b2b223cc3e6c2ddd1a94f098c44457&oe=5748C6D2
                                            [width] => 720
                                        )

                                )

                            [target] => stdClass Object
                                (
                                    [id] => 10153413586308403
                                    [url] => https://www.facebook.com/WorldArchery/videos/10153413586308403/
                                )

                            [type] => video_inline
                            [url] => https://www.facebook.com/WorldArchery/videos/10153413586308403/
                        )

                )

        )

    ...
)

I'm getting post information from a facebook page this way.

Init the Facebook class:

$this->facebook = new Facebook([
  'app_id' => $app_id,
  'app_secret' => $app_secret,
  'default_graph_version' => 'v2.5',
  //'default_access_token' => '{access-token}', // optional
]);

Getting post data:

...
$fields = array(
  'id',
  'application',
  'call_to_action',
  'caption',
  'created_time',
  'description',
  'from',
  'icon',
  'is_hidden',
  'is_published',
  'link',
  'message',
  'message_tags',
  'name',
  'object_id',
  'picture',
  'full_picture',
  'place',
  'privacy',
  'properties',
  'source',
  'status_type',
  'story',
  'story_tags',
  'targeting',
  'to',
  'type',
  'updated_time',
  'with_tags',
  'actions',
  // 'tags',
  // 'object_attachment',
  'feed_targeting',
  'attachments',
);
$data = $this->facebook->get($id . '?fields=' . implode(',', $fields));
$item = json_decode($data->getBody());
$object (object) $item;
jorgetutor
  • 460
  • 1
  • 3
  • 9
  • Appending an access token is of no use – you are not making an API request here, but are requesting a resource from their CDN, and that doesn’t use access tokens. // Have you tried adding the “usual” request headers to make your request look like it came from a real browser – stuff such as `User-Agent`, etc. …? – CBroe Jan 22 '16 at 14:50

1 Answers1

0

Ty to set the UA like @CBroe mentioned:

wget -U Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36 {your-url}

You may consider using cURL as an alternative: Saving image from PHP URL

Community
  • 1
  • 1
Hupfauer
  • 591
  • 1
  • 4
  • 15