Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

php - Validate a Facebook page URL

For an application I am developing, we allow users to add a link to their Facebook Page (strictly page, not Profile, not Group, only a Page).

I cannot find anything about validating whether the URL I received (server-side, PHP) is actually a valid Page URL.

Even better if I can get the "true" URL information, i.e. minus the #! if there is one. I can manage this with some parsing but I'd rather Facebook tell me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Unfortunately, there is no way around parsing the url unless you can ask them just for the id or username. If you cannot do that, they ask for the url, parse out either the username or page id. It would either be cocacola or 122456743. From there use the graph api:

http://graph.facebook.com/cocacola or http://graph.facebook.com/122456743 in either case you will get the following JSON back:

{
   "id": "40796308305",
   "name": "Coca-Cola",
   "picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs236.ash2/50516_40796308305_7651_s.jpg",
   "link": "http://www.facebook.com/coca-cola",
   "category": "Consumer_products",
   "website": "http://www.coca-cola.com",
   "username": "coca-cola",
   "products": "Coca-Cola is the most popular and biggest-selling soft drink in history, as well as the best-known product in the world.

Created in Atlanta, Georgia, by Dr. John S. Pemberton, Coca-Cola was first offered as a fountain beverage by mixing Coca-Cola syrup with carbonated water. Coca-Cola was introduced in 1886, patented in 1887, registered as a trademark in 1893 and by 1895 it was being sold in every state and territory in the United States. In 1899, The Coca-Cola Company began franchised bottling operations in the United States.

Coca-Cola might owe its origins to the United States, but its popularity has made it truly universal. Today, you can find Coca-Cola in virtually every part of the world.",
   "fan_count": 17367199
}

Next, to determine if it is a page or a user just check for the presence of the "category" property. Every page will have a category. User profiles will never have the category property.

You could also use FQL, but that is a bit more complicated and not really needed. http://developers.facebook.com/docs/reference/fql/page


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...