ulthane — 2012-02-05T14:54:12-05:00 — #1
I found a solution to exctract a page title from a URL:
$x = file_get_contents($URL);
preg_match("/<title>(.+?)<\\/title>/", $x, $match);
However, when trying on facebook it didnt work, it returned "Incompatible Browser | Facebook", is there another way to get this work on every site including FB?
cups — 2012-02-05T19:21:52-05:00 — #2
sogo7 — 2012-02-05T20:35:54-05:00 — #3
Facebook is not your typical website and it will take a bit more than file_get_contents to extract any data from a page. Both cookies and an AJAX call are involved with opening a page so it's probably a job for [cURL. Failing that Facebook does have a [URL="http://developers.facebook.com/docs/"]developers API](http://curl.haxx.se/) and you may be able to get the information you want through that a whole lot easier.
ulthane — 2012-02-06T05:03:19-05:00 — #4
Thank you both for the answers
but i dont think meta tags is what i need, because meta tag is not always the same as a page tite... (facebook is an example, each page has different titlte but all got the same meta description...)
What developer API do they have that will enable me to get a page title from them?
system — 2012-02-06T08:48:36-05:00 — #5
go into page source and You will find title tag and text between the tag will be the title of that page
starlion — 2012-02-06T08:58:59-05:00 — #6
What data specifically are you trying to get? If it's something that can be retrieved using the API's, use that. If it isnt, you're violating Facebook's Terms of Service and we cannot support you in this script. Facebook clearly states that you may not '...access Facebook...using automated means (such as harvesting bots, robots, spiders, or scrapers) without our permission.'
ulthane — 2012-02-06T09:08:34-05:00 — #7
I tried searching their API and i couldn't find it, but i dont know if i search the right way...
I'm simply trying to retrive a specific page title from their site to put in a link tag (like this: <a href="www.some-facebook.page.com">the page title</a>)
Each page of facebook has a title given by the creator of the page, which is the best way to describe the link i wanna put...
ulthane — 2012-02-06T09:53:39-05:00 — #8
Issue solved...all i need was adding this line...
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:126.96.36.199) Gecko/2009060215 Firefox/3.0.11');
starlion — 2012-02-06T10:04:18-05:00 — #9
It's still a violation of Facebook's ToS.
ulthane — 2012-02-06T10:32:25-05:00 — #10
Yes you're right, I don't really get the point but anyway, i've changed it so every url that includes fb in it will be named "facebook"
Anyway all pages that do not have public rights are named like this.
serverstorm — 2012-02-06T12:08:40-05:00 — #11
Hi, have you thought about trying to contact Facebook for permission? If what you are doing is actually quite benign then they may allow it. To date I have asked for such permission from Coca-Cola, Nautilus Equipment, and Google and in each case they granted me limited rights but enough for what I needed to do. This way you don't have to worry about it, especially if someone challenges you.