Skip to content

Commit 172d3e3

Browse files
authored
Added note to readme about user agent string and updated example (#29)
1 parent 2ee855f commit 172d3e3

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ _HTML code is formatted just for displaying purposes. You may choose between HTM
130130

131131
You can run the test suite by running `phpunit` from the command line.
132132

133+
## FAQ
134+
135+
**I don't get any information from a webpage, but Facebook shows information for the same URL. What do I do wrong?**
136+
137+
It seems that some pages (like Twitter) only publish OpenGraph information if Facebook's user agent string `facebookexternalhit/1.1` is used (see #28). So you should configure your PSR-18 client to use this user agent string:
138+
139+
```php
140+
$client = new Psr18Client(new NativeHttpClient([ "headers" => [ "User-Agent" => "facebookexternalhit/1.1" ] ]));
141+
```
142+
133143
## License
134144

135145
This library is licensed under the MIT license.

examples/consume_website.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// Initialize new Psr\HttpClient implementation. This example uses Symfony's implementation from the symfony/http-client
99
// package but you can use any implementation provided by your framework of choice.
10-
$client = new Psr18Client(new NativeHttpClient());
10+
$client = new Psr18Client(new NativeHttpClient([ "headers" => [ "User-Agent" => "facebookexternalhit/1.1" ] ]));
1111

1212
// Create a new crawler
1313
$crawler = new Fusonic\OpenGraph\Consumer($client, $client);

0 commit comments

Comments
 (0)